package yamaia.musicPlayerTester;

import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.BlockingQueue;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.database.Cursor;
import android.hardware.Camera;
import android.location.Location;
import android.location.LocationListener;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
import android.net.wifi.WifiConfiguration.GroupCipher;
import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.net.wifi.WifiConfiguration.PairwiseCipher;
import android.net.wifi.WifiConfiguration.Protocol;
import android.os.BatteryManager;
import android.os.Bundle;
import android.os.Handler;
import android.provider.MediaStore;
import android.provider.MediaStore.Audio.Albums;
import android.provider.MediaStore.Images.Media;
import android.provider.MediaStore.Video;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.webkit.ConsoleMessage;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.LinearLayout;




public class musicPlayerTester extends customTabActivity {
    /** Called when the activity is first created. */
    private static String path1 = "/mnt/sdcard/Blue Bossa-Lasid.mp3";
    private static String path2 = "/mnt/sdcard/Soulmate-Monla.mp3";
    private static String TAG = "musicPlayerTester";
    ArrayList<yamaiaMediaPlayer> testerPlayer = new ArrayList<yamaiaMediaPlayer>();
    customTabHost tabHost;
    static private Class<?> _intent;
    private static musicPlayerTester instance = null;
//    ArrayList<SensorEventListener> sel = new ArrayList<SensorEventListener>();
    //private MWSBroadcastReceiver m_receiver = new MWSBroadcastReceiver();
	private static final String MWSSYNCFOLDER = "/MWSAutoSync/";
	BatteryStatusReceiver m_betterybreceiver;
	Handler m_Handler = new Handler();
	Activity m_Context;
	int m_battLevel = -1;
	
private LocationListener m_GPSListener = new LocationListener() {
		
		@Override
		public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
			// TODO Auto-generated method stub
			
		}
		
		@Override
		public void onProviderEnabled(String arg0) {
			// TODO Auto-generated method stub
			
		}
		
		@Override
		public void onProviderDisabled(String arg0) {
			// TODO Auto-generated method stub
			
		}
		
		@Override
		public void onLocationChanged(Location location) {
			// TODO Auto-generated method stub
			double m_latitude = location.getLatitude();
			double m_longitude = location.getLongitude();

			m_latitude = location.getLatitude();
			m_longitude = location.getLongitude();
			
			Log.d("reavelv", "1m_latitude = " + m_latitude);
			Log.d("reavelv", "1m_longitude = " + m_longitude);
		}
	};
    
    Uri contentUri = Uri.withAppendedPath(
    		Uri.parse("content://mms-sms"), "conversations").buildUpon().appendQueryParameter("simple", "true").build();
    
    public class SyncFolder {
    	public String m_FolderName;
    	public ArrayList<FileInfomation> m_FileList;
    	public ArrayList<SyncFolder> m_FolderList;
    	
    	SyncFolder(String folderPath){
    		m_FolderName = folderPath;
    		m_FileList = new ArrayList<FileInfomation>();
    		m_FolderList = new ArrayList<SyncFolder>();
    	}
    	
    	void addFolder(SyncFolder childFolder){
    		m_FolderList.add(childFolder);
    	}
    	void addFile(FileInfomation innerFile){
    		m_FileList.add(innerFile);
    	}

    }
    
    

	private class QueuingThread extends Thread {
		private BlockingQueue<String> queue;

		public QueuingThread(BlockingQueue<String> queue) {
				super();
				this.queue = queue;
		}

		@Override
		public void run() {
			
		}
		
	}
    
    
    
    class FileInfomation{
		String FileName;
		String FileType;
		public FileInfomation(String name, String type) {
			// TODO Auto-generated constructor stub
			FileName = name;
			FileType = type;
		}
		String PrintFileInfo(){
			return "name = " + FileName + ", type = " + FileType;
		}
	}
    public static musicPlayerTester gettmpInstance() {
        if(instance==null) instance = new musicPlayerTester();
        return instance;
    }
    public Map<String, Object> getLocaleFolder(String path){
    	String DOCUMENT_ROOT = "/mnt/sdcard";
    	final File dir = new File(DOCUMENT_ROOT + path);

		final Map<String, Object> item = new HashMap<String, Object>();
		Log.d("reavelv", "getAbsolutePath = " + dir.getAbsolutePath());
		try {
			Log.d("reavelv", "getCanonicalPath = " + dir.getCanonicalPath());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Log.d("reavelv", "getParent = " + dir.getParent());
		Log.d("reavelv", "getName = " + dir.getName());
		Log.d("reavelv", "getPath = " + dir.getPath());
		Log.d("reavelv", "getTotalSpace = " + dir.getTotalSpace());
		Log.d("reavelv", "getUsableSpace = " + dir.getUsableSpace());
		Log.d("reavelv", "getFreeSpace = " + dir.getFreeSpace());
		Log.d("reavelv", "length = " + dir.length());
		if (dir.isDirectory() && dir.canRead()) {
			final File[] files = dir.listFiles(new FileFilter() {
				@Override
				public boolean accept(final File pathname) {
					return (pathname.isHidden() ? false : true);
				}
			});
			
			
			for (File file : files) {
				if (file.isDirectory()) {
					item.put(file.getName(), new FileInfomation(file.getName(), "dir"));
					
				} else {
					item.put(file.getName(), new FileInfomation(
								file.getName(), file.getName().substring(file.getName().lastIndexOf('.') + 1)));

				}
			} // for
		}
		
		return item;
    }
    

    
    @Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		Log.w("reavelv", "onPause");
//		SensorManager sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
//		List<Sensor> smList = sm.getSensorList(Sensor.TYPE_ALL);		
//		for(int l = 0 ; l < smList.size() ; l++){
//			sm.unregisterListener(sel.get(l));
//		}
		//unregisterReceiver(m_receiver);
		//c1.release();
	}
    
    
    
    @Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		Log.i("reavelv", "onActivityResult");
		Log.d("reavelv", "requestCode = " + requestCode);
		Log.d("reavelv", "resultCode = " + resultCode);
		Log.d("reavelv", "data = " + data);
		if(RESULT_OK == resultCode){
			
		}
	}



	WebView wv;
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        requestWindowFeature(Window.FEATURE_NO_TITLE);

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        
        
        
        
        /*
        // 미등록 단말 체크.
//			String reg = (String) mGetSysemProperty.invoke(null, new Object[] {"REG"});
//			String auth = (String) mGetSysemProperty.invoke(null, new Object[] {"AUTH"});
//			if (reg == null || auth == null || reg.equals("0") || auth.equals("0")) {
//				mErrorMsg = mContext.getString(R.string.err_unsubscribed);
//				return false;
//			}
        // 비행모드 체크.
//			if (Settings.System.getInt(mContext.getContentResolver(),Settings.System.AIRPLANE_MODE_ON, 0) != 0) {
//				mErrorMsg = mContext.getString(R.string.err_aiplain_mode);
//				return false;
//			}

        // Roaming 상태에서 WIFI 상태인지 체크.
//			if (!mGetSysemProperty.invoke(null, new Object[] {"ROAMING_AREA"}).equals("0")) {
//		        //LTE 지원 단말 Roaming 상태에서 WIFI 상태일때는 IWLAN을 통해서 접속하도록 변경 2011.09.15 
//				ConnectivityManager connMgr = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
//		        NetworkInfo netInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
//		        if( !netInfo.isConnected() )
//		        {
//		        	mErrorMsg = mContext.getString(R.string.err_roamingarea);
//					return false;
//		        }
//			}
        */
        
        
        
        
        
        
//        PackageManager pm = getPackageManager();
//		List<PackageInfo> packages = pm.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
//		for(PackageInfo info : packages){
//			Log.d("reavelv", info.packageName);
//			Log.w("reavelv", info.applicationInfo.name);
//			Log.w("reavelv", info.applicationInfo.backupAgentName);
//			Log.w("reavelv", info.applicationInfo.processName);
//			Log.w("reavelv", info.applicationInfo.taskAffinity);
//			if(info.packageName.contains("com.lguplus.ubivelox.car.widget")){
//				Log.w("reavelv", info.packageName);
//				Log.w("reavelv", info.applicationInfo.name);
//			}
//		}
        
//        Log.d("reavelv", "" + MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString());
//        finish();
        
//        Intent iii = new Intent(Intent.ACTION_PICK);
//        iii.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
//        startActivityForResult(iii, 0);
//        if(true){
//        	return;
//        }
        
        
        
        if(false){
	        ConnectivityManager cma = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
	        NetworkInfo neta = cma.getActiveNetworkInfo();
	        Log.d("reavelv", "type = " + neta.getType());
	        Log.d("reavelv", "typename = " + neta.getTypeName());
	        
	        /**
	         *   type = 0
	         *   typename = mobile
	         *   
	         *   
	         *   
	         *   
	         */
	        finish();
	        return;
        }
        Button bt = new Button(this);
        bt.setOnTouchListener(new OnTouchListener() {
			
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				// TODO Auto-generated method stub
				int action = event.getAction();
				Log.d("reavelv", "action = " + action);
				return false;
			}
		});

        
        Cursor c = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, "_data like '/mnt/sdcard/DCIM%'", null, null);
		if(c.moveToFirst()){
			do{
				try{
					for(String str : c.getColumnNames()){
						Log.w("reavelv", str + " = " + c.getString(c.getColumnIndex(str)));
					}
				}
				catch(NullPointerException e){}
				
				try{
					
				}
				catch(NullPointerException e){}
			}while(c.moveToNext());
		}

//		Date time = new Date(System.currentTimeMillis());
		//Log.d("reavelv", "1 " + time.getMonth() + "/" + time.getDate() + " - " + time.getHours() + ":" + time.getMinutes() +
		//		":" + time.getSeconds());
		//Log.d("reavelv" , "1 milsec = " + time.getTime());
		
//		int brightness = 255;
//		if(brightness < 1)
//			brightness = 1;
//		else if(brightness > 255)
//			brightness = 255;
//		android.provider.Settings.System.putInt(getContentResolver(), 
//				android.provider.Settings.System.SCREEN_BRIGHTNESS, brightness);
//		Window window = getWindow();
//		if(brightness == 0)
//			window.getAttributes().screenBrightness = 0.05f;
//		else
//			window.getAttributes().screenBrightness = (float)((float)brightness / 255);
		
		
		

//		Log.d("reavelv" ,"11111");
//		Intent intent = new Intent("com.lguplus.android.mws.upnp.UPnPServiceShutDown");
//        startService(intent);
//        finish();
//        Log.d("reavelv" ,"22222");
//        if(true)
//        	return;
//
//		Intent intent = new Intent( Intent.ACTION_MAIN, null );
//		intent.addCategory( "android.intent.category.LGUPLUSMWS" );//"android.intent.category.LAUNCHER"
//		intent.addCategory("android.intent.category.LAUNCHER");
//        List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities( intent, 0 );
//        if( resolveInfos == null ) resolveInfos = new ArrayList<ResolveInfo>();
//        int full_cnt    = resolveInfos.size();
//        if( full_cnt < 1 ) {
//            Log.e("reavelv","local full_cnt is 0");
//            return;
//        }
//        for( int full_idx = 0; full_idx < full_cnt; ++ full_idx ) {
//            ResolveInfo     rinfo   = resolveInfos.get( full_idx );
//            ActivityInfo    ainfo   = rinfo.activityInfo;
//            String label = ainfo.loadLabel(getPackageManager()).toString();
//            Log.e("reavelv","local title = " + label );
//            
//            if(!label.equals("Facebook"))
//            	continue;
//            Resources ress = null;
//            try {
//                ress = getPackageManager().getResourcesForApplication(ainfo.packageName);
//            } catch (NameNotFoundException e) {
//                // TODO Auto-generated catch block
//                e.printStackTrace();
//            }
//            
//            String          mws_url = null;
//            int rid = ress.getIdentifier("mws_url", "string", ainfo.packageName);
//            if(rid != 0) mws_url = ress.getString(rid);
//            if(mws_url != null) mws_url = Base64.encodeToString( mws_url.getBytes(), Base64.DEFAULT );
//            else mws_url = "";
//            
//            Drawable    drawable    = ainfo.loadIcon(getPackageManager());
//            if( drawable == null ) drawable = getPackageManager().getDefaultActivityIcon();
//            Bitmap      bitmap      = Bitmap.createBitmap( 60, 60, Bitmap.Config.ARGB_8888 );
//            if( bitmap != null ) {
//                Canvas  canvas      = new Canvas( bitmap );
//                drawable.setBounds( 0, 0, 72, 72 );
//                drawable.draw( canvas );
//                ByteArrayOutputStream out = new ByteArrayOutputStream( bitmap.getWidth() * bitmap.getHeight() * 4 );
//                try {
//                    bitmap.compress( Bitmap.CompressFormat.JPEG, 100, out );
//                    bitmap.compress( Bitmap.CompressFormat.JPEG, 90, out );
//                    out.flush();
//                    out.close();
//                    String iconStr = Base64.encodeToString(out.toByteArray(), Base64.DEFAULT);
//                    Log.d("reavelv", "iconSize = " + iconStr.length());
//                    Log.d("reavelv", iconStr);
//                }
//                catch( Exception e ) {
//                    bitmap = null;
//                }
//            }
//        }

//	    Intent intent1 = new Intent (Intent.ACTION_CALL,Uri.parse("tel:"+"01077995308"));
//        Intent intent1 = new Intent("android.intent.action.CALL_PRIVILEGED");
//        Intent intent = new Intent(Intent.ACTION_MAIN);
//        intent.setComponent(new ComponentName("com.lguplus.appstore", "com.lguplus.appstore.StoreMain"));
//        intent.addCategory(Intent.CATEGORY_LAUNCHER);
//        startActivity(intent);
        
//        Intent intent1 = new Intent (Intent.ACTION_WEB_SEARCH, Uri.parse ( "http://www.google.co.kr/"));
//        intent1.setData(Uri.parse("tel:01063385308"));
//	    startActivity(intent1);

        
        setContentView(R.layout.tabhostlayout);
        gettmpInstance();
        LinearLayout ll = (LinearLayout) findViewById(R.id.LinearLayout00);
        wv = new WebView(this);
        wv.setLayoutParams(new LayoutParams(480, 300));
        WebSettings ws = wv.getSettings();
        ws.setJavaScriptEnabled(true);
        wv.setWebChromeClient(new WebChromeClient(){

			@Override
			public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
				// TODO Auto-generated method stub
				Log.d("reavelv", "onConsoleMessage1 + consoleMessage.toString() = " + consoleMessage.toString());
				
				return super.onConsoleMessage(consoleMessage);
			}

			@Override
			public void onConsoleMessage(String message, int lineNumber,
					String sourceID) {
				// TODO Auto-generated method stub
				Log.d("reavelv", "onConsoleMessage2 message = " + message + " lineNumber = " + lineNumber
						 + " sourceID = " + sourceID);
				super.onConsoleMessage(message, lineNumber, sourceID);
			}
        	
        });
        
//        ll.addView(wv);
        wv.loadUrl("file:///android_asset/www/index.html");
        wv.loadUrl("javascript:testWebfunction(" + 30 + ")");
        ObjectIntent puttabHostIntent = new ObjectIntent();
        puttabHostIntent.setClass(this, FirstT.class);
        puttabHostIntent.putExtra("tabHost", tabHost);
        tabHost = getTabHost(); 
        tabHost.addTab(tabHost.newTabSpec("Tab1").setIndicator("tab1",
        		getResources().getDrawable(R.drawable.star_big_on), R.drawable.shape1).
        		setContent(puttabHostIntent));

        puttabHostIntent = new ObjectIntent();
        puttabHostIntent.setClass(this, secT.class);
        puttabHostIntent.putExtra("tabHost", tabHost);
        
        tabHost.addTab(tabHost.newTabSpec("Tab2").setIndicator("tab2",
        		R.drawable.test).setContent(puttabHostIntent));
        tabHost.addTab(tabHost.newTabSpec("Tab3").setIndicator("tab3",
        		R.drawable.test1).setContent(R.id.view3));
        
        tabHost.addTab(tabHost.newTabSpec("Tab4").setIndicator("tab4",
        		getResources().getDrawable(R.drawable.star_big_on), R.drawable.js).setContent(R.id.linear));
        /*
        ArrayList<String> IPList = new ArrayList<String>();
		try {
			Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
			
            for (NetworkInterface ni : Collections.list(nis))
            {
                Enumeration<InetAddress> iis = ni.getInetAddresses();
        		Log.d("reavelv", "displayname = " + ni.getDisplayName());
        		Log.d("reavelv", "getName = " + ni.getName());
        		try{
        			Log.d("reavelv", "getMTU = " + ni.getMTU());
        		}catch (NoSuchMethodError e){
        			Log.e("reavelv", e.getMessage());
        		}
        		Log.d("reavelv", "toString = " + ni.toString());
                for (InetAddress ia : Collections.list(iis))
                {
                	if(ia instanceof Inet6Address )
                		Log.d("reavelv", "six");
                	else if (ia instanceof Inet4Address)
                		Log.d("reavelv", "four");
        			Log.d("reavelv", "ia.getHostName() = " + ia.getHostName());
        			byte[] addr = ia.getAddress();
        			StringBuilder sb = new StringBuilder();
        			for(int k = 0 ; k < addr.length ; k++){
        				sb.append("[" + addr[k] + "]");
        			}
        			Log.d("reavelv", "getAddress() = " + sb.toString());
        			Log.d("reavelv", "getHostAddress() = " + ia.getHostAddress());
        			Log.d("reavelv", "getCanonicalHostName() = " + ia.getCanonicalHostName());
        			Log.d("reavelv", "toString() = " + ia.toString());
                	
                	if(!ia.getHostAddress().equals("127.0.0.1"))
                		IPList.add(ia.getHostAddress());
                }
            }
		} catch (SocketException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		Log.d("reavelv", "tttttttttttttttttttttttttttttttttttt");
		for(String ip : IPList){
			Log.d("reavelv", ip);
		}
		Log.d("reavelv", "tttttttttttttttttttttttttttttttttttt");
		time = new Date(System.currentTimeMillis());
		*/
		
		TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
		Log.d("reavelv", "==================================================================================");
//		try {
//			PermissionInfo pi = getPackageManager().getPermissionInfo(permission.ACCESS_WIFI_STATE, PackageManager.GET_PERMISSIONS);
//			Log.d("reavelv", "name = " + pi.name);
//			Log.d("reavelv", "group = " + pi.group);
//			Log.d("reavelv", "packageName = " + pi.packageName);
//			Log.d("reavelv", "descriptionRes = " + pi.descriptionRes);
//			Log.d("reavelv", "icon = " + pi.icon);
//			Log.d("reavelv", "protectionLevel = " + pi.protectionLevel);
//			pi = getPackageManager().getPermissionInfo(permission.INTERNET, PackageManager.GET_PERMISSIONS);
//			Log.d("reavelv", "==================================================================================");
//			Log.d("reavelv", "name = " + pi.name);
//			Log.d("reavelv", "group = " + pi.group);
//			Log.d("reavelv", "packageName = " + pi.packageName);
//			Log.d("reavelv", "descriptionRes = " + pi.descriptionRes);
//			Log.d("reavelv", "icon = " + pi.icon);
//			Log.d("reavelv", "protectionLevel = " + pi.protectionLevel);
//			Log.d("reavelv", "==================================================================================");
//		} catch (NameNotFoundException e1) {
//			Log.e("reavelv", "" + e1.getLocalizedMessage());
//			Log.e("reavelv", "" + e1.getMessage());
//			e1.printStackTrace();
//		}
//		Log.d("reavelv", "getApplicationInfo().permission = " + getApplicationInfo().permission);
//		tm.listen(new PhoneStateListener(){
//
//			@Override
//			public void onCallStateChanged(int state, String incomingNumber) {
//				// TODO Auto-generated method stub
//				Log.d("reavelv", "onCallStateChanged - ");
//				Log.d("reavelv", "state - " + state);
//				Log.d("reavelv", "incomingNumber - " + incomingNumber);
//				if(state == TelephonyManager.CALL_STATE_RINGING){
//					new Handler().postDelayed(new Runnable() {
//						
//						@Override
//						public void run() {
//							// TODO Auto-generated method stub
//							Log.d("reavelv", "run1 - ");
//							Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
//							intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
//							sendOrderedBroadcast(intent, null);
//						}
//					}, 5000);
//					Log.d("reavelv", "CALL_STATE_RINGING - ");
//				}
//				else if(state == TelephonyManager.CALL_STATE_OFFHOOK){
//					new Handler().postDelayed(new Runnable(){
//						
//						@Override
//						public void run() {
//							// TODO Auto-generated method stub
//							Log.d("reavelv", "run2 - ");
//							Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
//							intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
//							sendOrderedBroadcast(intent, null);
//						}
//					}, 5000);
//					
//					Log.d("reavelv", "CALL_STATE_OFFHOOK - ");
//				}
//				
//			}
//			
//		}, PhoneStateListener.LISTEN_CALL_STATE);
		

//		SensorManager sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
//		
//		List<Sensor> smList = sm.getSensorList(Sensor.TYPE_ALL);
//		Sensor.TYPE_ACCELEROMETER	1
//		Sensor.TYPE_MAGNETIC_FIELD	2
//		Sensor.TYPE_ORIENTATION		3
//		Sensor.TYPE_GYROSCOPE		4
//		Sensor.TYPE_LIGHT			5
//		Sensor.TYPE_PRESSURE		6
//		Sensor.TYPE_TEMPERATURE		7
//		Sensor.TYPE_PROXIMITY		8
		
//		for(int l = 0 ; l < smList.size() ; l++){
//			sel.add(new SensorEventListener() {
//				@Override
//				public void onSensorChanged(SensorEvent event) {
//					Log.d("reavelv", "accuracy = " + event.accuracy);
//					Date date = new Date(event.timestamp);
//					Log.d("reavelv", "timestamp = " + ((int)(date.getYear() + 1900)) + "-" + ((int)(date.getMonth() + 1)) + "-" + date.getDate()
//							 + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds());
//					Log.d("reavelv", "sensor = " + event.sensor.getName());
//					Log.d("reavelv", "sensortype = " + event.sensor.getType());
//					if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
//						Log.d("reavelv", "sensor = " + "TYPE_ACCELEROMETER");
//					else if(event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
//						Log.d("reavelv", "sensor = " + "TYPE_MAGNETIC_FIELD");
//					else if(event.sensor.getType() == Sensor.TYPE_ORIENTATION)
//						Log.d("reavelv", "sensor = " + "TYPE_ORIENTATION");
//					else if(event.sensor.getType() == Sensor.TYPE_GYROSCOPE)
//						Log.d("reavelv", "sensor = " + "TYPE_GYROSCOPE");
//					else if(event.sensor.getType() == Sensor.TYPE_LIGHT)
//						Log.d("reavelv", "sensor = " + "TYPE_LIGHT");
//					else if(event.sensor.getType() == Sensor.TYPE_PRESSURE)
//						Log.d("reavelv", "sensor = " + "TYPE_PRESSURE");
//					else if(event.sensor.getType() == Sensor.TYPE_TEMPERATURE)
//						Log.d("reavelv", "sensor = " + "TYPE_TEMPERATURE");
//					else if(event.sensor.getType() == Sensor.TYPE_PROXIMITY)
//						Log.d("reavelv", "sensor = " + "TYPE_PROXIMITY");
//					int x = 0;
//					for(float val:event.values){
//						Log.d("reavelv", "values" + x + " = " + val);
//						x++;
//					}
//				}
//				
//				@Override
//				public void onAccuracyChanged(Sensor sensor, int accuracy) {
//					Log.w("reavelv", "sensorname = " + sensor.getName());
//					Log.w("reavelv", "accuracy = " + accuracy);
//				}
//			});
//			sm.registerListener(sel.get(l), smList.get(l), SensorManager.SENSOR_DELAY_NORMAL);
//		}

//		Runtime runtime = Runtime.getRuntime();
//		try {
//			Process process = runtime.exec("top -n 1");
//			InputStream is = process.getInputStream();
//			InputStreamReader isr = new InputStreamReader(is);
//			BufferedReader br = new BufferedReader(isr);
//			String line = "";
//			String sb = "";
//			String[] testtmp = null;
//			while ((line = br.readLine()) != null) {
//                String segs = line.trim();
//                if(segs.length() > 0){
//                	sb = segs;
//                	testtmp = segs.split(", ");
//                	break;
//                }
//			}
//			for(int a = 0 ; a < testtmp.length ; a++){
//				Log.d("reavelv", testtmp[a] + "\n");
//			}
//			Log.d("reavelv", sb.toString());
//        
//			
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		
		/*
		ServiceLoader<CharsetProvider> cp = ServiceLoader.load(CharsetProvider.class, null);
		
		 Iterator<CharsetProvider> iii = cp.iterator();
		 Log.i("reavelv", "iii.toString() = " + iii.toString());
		 Log.i("reavelv", "hasNext() = " + iii.hasNext());
		 while(iii.hasNext()){
			 CharsetProvider csp = iii.next();
			 Iterator<Charset> sss = csp.charsets();
			 while(sss.hasNext()){
				 Charset charsss = sss.next();
				 Log.i("reavelv", "displayName = " + charsss.displayName());
				 Log.i("reavelv", "name = " + charsss.name());
				 Log.i("reavelv", "defaultCharset = " + charsss.defaultCharset());
			 }
			 
		 }
		 */
		/*
		File file = new File("/sdcard/media/DoctorMam/.classpath");
		
		FileInputStream fis;
		try {
			fis = new FileInputStream(file);
			String str = "";
			StringBuilder sb = new StringBuilder();
			BufferedReader br = new BufferedReader(new InputStreamReader(fis));
			while((str = br.readLine()) != null){
				Log.v("reavelv", "str = " + new String(str.getBytes("utf-8")));
				sb.append(str);
			}

			Log.i("reavelv", "sb = " + sb.toString());
			FileOutputStream out = new FileOutputStream("/sdcard/testtest/test.txt");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch(IOException e){
			
		}
		*/
		 
		
		
		//window.getAttributes().screenBrightness = 0.05f;
		
		
		//Log.d("reavelv", "2 " + time.getMonth() + "/" + time.getDate() + " - " + time.getHours() + ":" + time.getMinutes() +
		//		":" + time.getSeconds());
		//Log.d("reavelv" , "2 milsec = " + time.getTime());
		/*
		List<PackageInfo> packages = getPackageManager().getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);

		int mmsid = -1;
		//Log.d("reavelv", "packages.size() = " + packages.size());
		for(int i = 0; i < packages.size(); i++){
			//Log.d("reavelv", "app pack - " + packages.get(i).applicationInfo.packageName);
			if(packages.get(i).packageName.equals("com.gameloft.android.GAND.GloftDUNQ.DungeonHunter")){
				mmsid = i;
			}
			//com.android.mms
		}
		
		//ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
		/*
		List<RunningTaskInfo> Info = am.getRunningTasks(13);
		for(int i = 0 ; i < 13 ; i++){
			ComponentName topActivity = Info.get(i).topActivity;
			Log.d("reavelv", i + " : " + topActivity.getPackageName());
			
		}
		*/
		
		/*
    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
		List<RunningServiceInfo> Info = am.getRunningServices(30);
		for(int i = 0 ; i < Info.size() ; i++){
			ComponentName topActivity = Info.get(i).service;
			Log.d("reavelv", i + " getPackageName: " + topActivity.getPackageName());
			Log.d("reavelv", i + " getClassName: " + topActivity.getClassName());
			Log.d("reavelv", i + " getShortClassName: " + topActivity.getShortClassName());
			Log.d("reavelv", i + " toShortString: " + topActivity.toShortString());
			/*
21 getPackageName: com.lguplus.android.mws.webserver
21 getClassName: com.lguplus.android.mws.webserver.IJettyService
21 getShortClassName: .IJettyService
21 toShortString: {com.lguplus.android.mws.webserver/com.lguplus.android.mws.webserver.IJettyService}

			 */
			
		//}
		
		
		
		
		/*
		//ComponentName comp = new ComponentName("com.gameloft.android.GAND.GloftDUNQ.DungeonHunter", "com.gameloft.android.GAND.GloftDUNQ.DungeonHunter.GameInstaller");
		Intent intent = new Intent();
		//intent.setPackage(packages.get(mmsid).applicationInfo.packageName);
        intent.setComponent(new ComponentName("com.gameloft.android.GAND.GloftDUNQ.DungeonHunter", ".DungeonHunter"));
        //intent.setComponent(new ComponentName("com.gameloft.android.GAND.GloftDUNQ.DungeonHunter", 
        //		"com.gameloft.android.GAND.GloftDUNQ.DungeonHunter.GameInstaller"));
		intent.setPackage("com.gameloft.android.GAND.GloftDUNQ.DungeonHunter");
		*/
		
		/*
		Log.d("test", "test1");
		String MWS_WEBSERVER_ACTION = "com.lguplus.android.mws.webserver";
		Intent intent = new Intent();
		intent.setAction(MWS_WEBSERVER_ACTION);
		
		registerReceiver(m_receiver, new IntentFilter("com.lguplus.android.mws.webserver"));
		
		startService(intent);
		Log.d("test", "test1");
		*/
		
		/*
		String DOCUMENT_ROOT = "/mnt/sdcard";
		File dir = new File(DOCUMENT_ROOT + MWSSYNCFOLDER);
		Log.d("reavelv", "dir exist = " + dir.exists());
		if(!dir.exists()){
			Log.d("reavelv", "dir mkdir = " + dir.mkdir());
			
		}
		BlockingQueue<String> m_queue = new LinkedBlockingQueue<String>();
		QueuingThread qt = new QueuingThread(m_queue);
		qt.start();
		qt.interrupt();
		Log.d(TAG, "qt.isInterrupted() = " + qt.isInterrupted());
		Log.d(TAG, "qt.isAlive() = " + qt.isAlive());
		try {
			qt.join();
			Log.d(TAG, "InterruptedException1 " + qt.isAlive());
			qt.stop();
			Log.d(TAG, "InterruptedException2 " + qt.isAlive());
			
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			Log.d(TAG, "InterruptedException " + qt.isAlive());
		}
		
		
		
		
		Log.d(TAG, "test11111111111111111111111111");
		
		StringBuilder sb = new StringBuilder();
		sb.append("http://").append("127.0.0.1").append(":8080/console/DC/filemanager/?path=" + MWSSYNCFOLDER).append("&mode=getfolder");
		
		HttpGet httpGet = new HttpGet(sb.toString());
		httpGet.setHeader("Content-Type", "text/json");
		
		HttpClient client = new DefaultHttpClient();

		SyncFolder sf = new SyncFolder("video");
		SyncFolder diffsf = new SyncFolder("diff");
		
		try {
			HttpResponse response = client.execute(httpGet);
			if(response.getStatusLine().getStatusCode() == 200){
				HttpEntity he = response.getEntity();
				InputStream is = he.getContent();
				byte[] buf = new byte[1024];
				StringBuilder streamSB = new StringBuilder();
				for(int i ; (i = is.read(buf)) != -1 ; ){
					Log.i(TAG, "stream length = " + i);
					streamSB.append(new String(buf, 0, i));
				}
				Log.i(TAG, "path result!!!");
				Log.d(TAG, streamSB.toString());
				Log.i(TAG, "path result!!!");
				try {
					JSONObject jsobj = new JSONObject(streamSB.toString());
					Log.i(TAG, "jsobj.length()" + jsobj.length());
					Log.d(TAG, "jsobj.names().toString() = " + jsobj.names().toString());
					JSONArray jsArr = jsobj.names();
					for(int x = 0 ; x < jsobj.length() ; x++){
						Log.d(TAG, jsArr.get(x).toString());
						Log.d(TAG, jsobj.get(jsArr.get(x).toString()).toString());
						JSONObject jssss = new JSONObject(jsobj.get(jsArr.get(x).toString()).toString());
						Log.i(TAG, "jssss.names().toString() = " + jssss.names().toString());
						JSONArray jssssArr = jssss.names();
						String filename = null;	String filetype = null;
						for(int y = 0 ; y < jssss.length() ; y++){
							Log.e(TAG, jssss.get(jssssArr.get(y).toString()).toString());
							if(jssssArr.get(y).toString().equals("Filename")){
								filename = jssss.get(jssssArr.get(y).toString()).toString();
							}
							else if(jssssArr.get(y).toString().equals("File Type")){
								filetype = jssss.get(jssssArr.get(y).toString()).toString();
							}
						}
						if(!filetype.equals("dir"))
							sf.addFile(new FileInfomation(filename, filetype));
						
					}
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				Log.d(TAG, "m_FileList.size = " + sf.m_FileList.size());
				for(int xx = 0 ; xx < sf.m_FileList.size() ; xx++){
					Log.d(TAG, "m_FileList (" + xx + ") = " + sf.m_FileList.get(xx).PrintFileInfo());
				}
				
			}
			else{
				Log.d(TAG, "Error code - " + response.getStatusLine().getStatusCode());
			}
		}
		catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		Log.d(TAG, "test11111111111111111111111111");
		Map<String, Object> testmap = getLocaleFolder(MWSSYNCFOLDER);
		Log.d(TAG, "testmap.size = " + testmap.size());
		Log.d(TAG, "m_FileList.size = " + sf.m_FileList.size());
		for(int k = 0 ; k < sf.m_FileList.size() ; k++){
			try{
				if(k % 2 != 0){
					Log.w(TAG, ((FileInfomation)testmap.get(sf.m_FileList.get(k).FileName)).FileName);
				}
				else{
					Log.w(TAG, ((FileInfomation)testmap.get(sf.m_FileList.get(k).FileName + " ")).FileName);
				}
				
			} catch(NullPointerException e){
				Log.e(TAG, sf.m_FileList.get(k).FileName + " is not exist.");
				diffsf.m_FileList.add(sf.m_FileList.get(k));
			}
		}
		Log.v(TAG, "diffed");
		for(int l = 0 ; l < diffsf.m_FileList.size() ; l++){
			Log.v(TAG, "diffsf.m_FileList(" + l + ") = " + diffsf.m_FileList.get(l).FileName);
			String tmp = diffsf.m_FileList.get(l).FileName;

			Log.d(TAG, "found " + tmp);
			StringBuilder sbdown = new StringBuilder();
			
			sbdown.append("http://").append("127.0.0.1")
				.append(":8080/console/DC/filemanager?mode=download&path=" + MWSSYNCFOLDER)
				.append(tmp.replace(" ", "%20"));
			
			HttpGet httpGetdown = new HttpGet(sbdown.toString());
			httpGetdown.setHeader("Content-Type", "text/json");
			
			
			HttpClient clientDown = new DefaultHttpClient();
			
			try {
				HttpResponse response = clientDown.execute(httpGetdown);
				
				HttpEntity entity = response.getEntity();
				
				if(entity != null)
				{
					int xx = 1;
					Log.d(TAG, "1test" + xx);
					xx++;
					//tmp = tmp.replace("/", "%2");
					FileOutputStream out = new FileOutputStream("/mnt/sdcard" + MWSSYNCFOLDER + tmp);
					
					time = new Date(System.currentTimeMillis());
					Log.d(TAG, "time = " + time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds());
					Log.d(TAG, "System.currentTimeMillis() = " + System.currentTimeMillis());
					Log.d(TAG, "111111111111111111111111111111111111111111" + xx);
					
					InputStream instream = entity.getContent();
					
					byte[] b = new byte[2048];
					int n;
					long bytes = 0;
					while((n = instream.read(b)) >= 0)
					{
						Log.d(TAG, "5test" + xx);
						xx++;
						bytes += n;
						out.write(b, 0, n);
					}
					Log.d(TAG, "111111111111111111111111111111111111111111" + xx);
					Log.d(TAG, "time = " + time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds());
					Log.d(TAG, "System.currentTimeMillis() = " + System.currentTimeMillis());
					Log.d(TAG, "2test" + xx);
					xx++;
					out.close();
				}
				
			} catch (ClientProtocolException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
			
		}
		
		*/
		
		
		
		
		
		///console/DC/filemanager?mode=download&path=/sdcard/media/]
		/*
		int x = 0;
		Cursor c = getContentResolver().query(ContactsContract.Data.CONTENT_URI,null,null,null,null);
		Log.i("reavelv", "=================================================");
    	if(c.moveToFirst()){
    		while(true){
    			/*
	        	Log.d("reavelv", "_id = " + c.getInt(c.getColumnIndex("_id")));   
	        	String str = null;
	        	try{
	        		str = c.getString(c.getColumnIndex("number"));
		        	Log.d("reavelv", "number = " + str);  
	        	}
	        	catch (IllegalStateException e){
	        		
	        	}
	        	try{
	        		str = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
		        	Log.d("reavelv", "DISPLAY_NAME = " + str);  
	        	}
	        	catch (IllegalStateException e){
	        		
	        	}
	        		
	        	try{
	        		str = c.getString(c.getColumnIndex("name"));
		        	Log.d("reavelv", "name = " + str);  
	        	}
	        	catch (IllegalStateException e){
	        		
	        	}
	        	try{
		        	str = c.getString(c.getColumnIndex("display_name_alt"));
		        	Log.d("reavelv", "display_name_alt = " + str);  
	        	}
	        	catch (IllegalStateException e){
	        		
	        	}
	        	*//*
    			Log.i("reavelv", "-------------------");
    			for(int i = 0;i < c.getColumnNames().length;i++){
	        		try{
		        		String str = c.getString(c.getColumnIndex(c.getColumnNames()[i]));
			        	Log.d("reavelv", c.getColumnNames()[i] + " - " + str);  
		        	}
		        	catch (IllegalStateException e){
		        		
		        	}
		        	catch (SQLiteException e){
			        	//Log.d("reavelv", "SQLiteException = " + e);  
		        		//byte[] by = c.getBlob(c.getColumnIndex(c.getColumnNames()[i]));
			        	//Log.d("reavelv", "by = " + by);  
			        	//bmp = BitmapFactory.decodeByteArray(by, 0, by.length);
			        	//Log.d("reavelv", bmp.toString());  
		        		
		        	}
	        	}
	        	x++;
	        	c.moveToNext();
	        	if(x == c.getCount() || x == 50){
	            	Log.d("reavelv", "thread end ");           		
	        		break;
	        	}
    		}
    	}

		Log.i("reavelv", "=================================================");
    	/*
    	 * 
    	Cursor accountCursor = ctx.getContentResolver().query(SyncStateUri, null, null, null, null);


		if(accountCursor.moveToFirst()){
			for(int i = 1 ; i <= accountCursor.getCount() ; i++){
				String tmpString = null;
				try{	tmpString = accountCursor.getString(2);	} catch(Throwable t){}
				mAccounts.add(new ContactAccount(tmpString, accountCursor.getString(1)));
				accountCursor.moveToNext();
			}
		}
		
		accountCursor.close(); 
    	
    	*/
		//Uri MediaDataUri = Video.Media.EXTERNAL_CONTENT_URI;
		//Cursor c = getContentResolver().query(MediaDataUri,null,null,null,null);
		
//		Cursor c = getContentResolver().query(ContactsContract.Data.CONTENT_URI,null,null,null,null);
		//Cursor c = getContentResolver().query(ContactsContract.SyncState.CONTENT_URI, null, null, null, null);
//		Cursor c = getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI,null,null,null,null);
//		Cursor c = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null,null,null,null);
		int x = 0;
		if(c.moveToFirst()){
			do{
				x++;
//				Log.d("reavelv", "_id = " + c.getString(c.getColumnIndex("_id")));   
	        	String str = null;
	        	for(int i = 0;i < c.getColumnNames().length;i++){
	        		try{
		        		str = c.getString(c.getColumnIndex(c.getColumnNames()[i]));
//			        	Log.d("reavelv", c.getColumnNames()[i] + " - " + str);  
		        	}
		        	catch (IllegalStateException e){
		        		
		        	}
		        	catch(RuntimeException e){
		        		
		        	}
	        	}
	        	if( x > 200)
	        		break;
			}while(c.moveToNext());
		}
		
		
		/*
		Uri ContactDataUri = ContactsContract.Data.CONTENT_URI;
		int primaryDataID = -1;
		ArrayList<Integer> DataID = null;
		Cursor DataIDCursor = getContentResolver().query(ContactDataUri, 
				new String[]{ ContactsContract.Data._ID , 
					ContactsContract.Data.IS_PRIMARY,
					ContactsContract.Data.DATA1
				}, 
				ContactsContract.Data.RAW_CONTACT_ID + "=" + 95 + " AND " + 
				ContactsContract.Data.MIMETYPE + " like '" + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE + "'", 
				null, null);
		if(DataIDCursor.moveToFirst()){
			DataID = new ArrayList<Integer>();
			for(int i = 0 ; i < DataIDCursor.getCount() ; i++){
				DataID.add(DataIDCursor.getInt(0));
				Log.d("reavelv", i + " data1 = " + DataIDCursor.getString(2));
				if(DataIDCursor.getInt(1) == 1)
					primaryDataID = DataIDCursor.getInt(0);
			}
			DataIDCursor.close();
		}
		if(DataID != null && DataID.size() > 0 && primaryDataID == -1)
			primaryDataID = DataID.get(0);
			
        //int x = 0;
    	//Log.d("reavelv", "" + c.getCount());   
    	/*
    	for(int i = 0 ; i < c.getColumnNames().length ; i++){
    		Log.d("reavelv", "" + c.getColumnNames()[i]); 
    	}
    	Bitmap bmp = null;
    	if(c.moveToFirst()){
    		while(true){
	        	Log.d("reavelv", "_id = " + c.getString(c.getColumnIndex("_id")));   
	        	String str = null;
	        	for(int i = 0;i < c.getColumnNames().length;i++){
	        		try{
		        		str = c.getString(c.getColumnIndex(c.getColumnNames()[i]));
			        	Log.d("reavelv", c.getColumnNames()[i] + " - " + str);  
		        	}
		        	catch (IllegalStateException e){
		        		
		        	}
		        	catch (SQLiteException e){
			        	//Log.d("reavelv", "SQLiteException = " + e);  
		        		//byte[] by = c.getBlob(c.getColumnIndex(c.getColumnNames()[i]));
			        	//Log.d("reavelv", "by = " + by);  
			        	//bmp = BitmapFactory.decodeByteArray(by, 0, by.length);
			        	//Log.d("reavelv", bmp.toString());  
		        		
		        	}
	        	}
	        	
	        	
	        	x++;
	        	c.moveToNext();
	        	if(x == c.getCount()){
	            	Log.d("reavelv", "thread end ");           		
	        		break;
	        	}
    		}
//    		if(bmp != null){
//    			Log.d("reavelv", "bmp test");
//    			ImageView iv = (ImageView) findViewById(R.id.imgviewer);
//    			iv.setImageBitmap(bmp);
//    		}
//    		for(int j = 0;j < 20;j++){
//	        	Log.d("reavelv", "_id = " + c.getString(c.getColumnIndex("_id")));   
//	        	String str = null;
//	        	for(int i = 0;i < c.getColumnNames().length;i++){
//	        		try{
//		        		str = c.getString(c.getColumnIndex(c.getColumnNames()[i]));
//			        	Log.d("reavelv", c.getColumnNames()[i] + " - " + str);  
//		        	}
//		        	catch (IllegalStateException e){
//		        		
//		        	}
//	        	}
//	        	
//	        	
//	        	x++;
//	        	c.moveToNext();
//	        	if(x == c.getCount()){
//	            	Log.d("reavelv", "thread end ");           		
//	        		break;
//	        	}
//    		
//    		}
    		
    	}
    	
		Log.d("reavelv", "test11111111111111111111111111");
		
		/*
		 * 09-14 09:32:46.380: DEBUG/reavelv(1257): 4
09-14 09:32:46.380: DEBUG/reavelv(1257): display_name_reverse
09-14 09:32:46.380: DEBUG/reavelv(1257): times_contacted
09-14 09:32:46.380: DEBUG/reavelv(1257): custom_ringtone
09-14 09:32:46.380: DEBUG/reavelv(1257): primary_organization
09-14 09:32:46.380: DEBUG/reavelv(1257): phonetic_name
09-14 09:32:46.380: DEBUG/reavelv(1257): status
09-14 09:32:46.380: DEBUG/reavelv(1257): label
09-14 09:32:46.380: DEBUG/reavelv(1257): number
09-14 09:32:46.380: DEBUG/reavelv(1257): type
09-14 09:32:46.380: DEBUG/reavelv(1257): mode
09-14 09:32:46.380: DEBUG/reavelv(1257): last_time_contacted
09-14 09:32:46.380: DEBUG/reavelv(1257): display_name
09-14 09:32:46.380: DEBUG/reavelv(1257): im_handle
09-14 09:32:46.380: DEBUG/reavelv(1257): _id
09-14 09:32:46.380: DEBUG/reavelv(1257): number_key
09-14 09:32:46.380: DEBUG/reavelv(1257): starred
09-14 09:32:46.384: DEBUG/reavelv(1257): primary_email
09-14 09:32:46.384: DEBUG/reavelv(1257): name
09-14 09:32:46.384: DEBUG/reavelv(1257): display_name_alt
09-14 09:32:46.384: DEBUG/reavelv(1257): primary_phone
09-14 09:32:46.384: DEBUG/reavelv(1257): im_account
09-14 09:32:46.384: DEBUG/reavelv(1257): notes
09-14 09:32:46.384: DEBUG/reavelv(1257): im_protocol
09-14 09:32:46.384: DEBUG/reavelv(1257): send_to_voicemail

		 */
		
    	/*
    	if(c.moveToFirst()){
    		while(true){
	        	Log.d("reavelv", "_id = " + c.getInt(c.getColumnIndex("_id")));   
	        	Log.d("reavelv", "_data = " + c.getString(c.getColumnIndex("_data")));  
	        	
	        	x++;
	        	c.moveToNext();
	        	if(x == c.getCount()){
	            	Log.d("reavelv", "thread end ");           		
	        		break;
	        	}
    		}
    	}
        Log.d("reavelv", "VERSION.RELEASE: " + Build.VERSION.RELEASE);  Version
		Log.d("reavelv", "ANDROID_ID = " + Secure.getString(getContentResolver(), Secure.ANDROID_ID));  UUID
        Log.d("reavelv", "PRODUCT: " + Build.PRODUCT);  Name
    	*/
		
//		LocationManager m_Location = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
//		
//		Criteria m_criteria = new Criteria(); // Criteria占쏙옙占쎄쑴��占쎈베�ョ몴占썲첎占쎌죬占쏙옙占쏙옙�⑥쥓��옙�롫뮉 占쎈벊��占쎈베猷꾣에占쏙옙�룹퍟占쎌꼶��占쎌뮆��
//		m_criteria.setAccuracy(Criteria.ACCURACY_COARSE);
//		m_criteria.setPowerRequirement(Criteria.POWER_LOW);
//		m_criteria.setAltitudeRequired(false);
//		m_criteria.setBearingRequired(false);
//		m_criteria.setSpeedRequired(false);
//		m_criteria.setCostAllowed(true);
//		String provider = m_Location.getBestProvider(m_criteria, true);
		
		
//		Location location = m_Location.getLastKnownLocation(LocationManager.GPS_PROVIDER);
//		double m_latitude = location.getLatitude();
//		double m_longitude = location.getLongitude();
		
//		Log.d("reavelv", "m_latitude = " + m_latitude);
//		Log.d("reavelv", "m_longitude = " + m_longitude);
		
//		m_Location.requestLocationUpdates(provider, 2000, 10, m_GPSListener);
		
		/*
		Log.d("reavelv", "ADB_ENABLED = " + Secure.getString(getContentResolver(), Secure.ADB_ENABLED));
		Log.d("reavelv", "ACCESSIBILITY_ENABLED = " + Secure.getString(getContentResolver(), Secure.ACCESSIBILITY_ENABLED));
		Log.d("reavelv", "ALLOW_MOCK_LOCATION = " + Secure.getString(getContentResolver(), Secure.ALLOW_MOCK_LOCATION));
		Log.d("reavelv", "ALLOWED_GEOLOCATION_ORIGINS = " + Secure.getString(getContentResolver(), Secure.ALLOWED_GEOLOCATION_ORIGINS));
		Log.d("reavelv", "ANDROID_ID = " + Secure.getString(getContentResolver(), Secure.ANDROID_ID));
		Log.d("reavelv", "BACKGROUND_DATA = " + Secure.getString(getContentResolver(), Secure.BACKGROUND_DATA));
		Log.d("reavelv", "BLUETOOTH_ON = " + Secure.getString(getContentResolver(), Secure.BLUETOOTH_ON));
		Log.d("reavelv", "DATA_ROAMING = " + Secure.getString(getContentResolver(), Secure.DATA_ROAMING));
		Log.d("reavelv", "DEVICE_PROVISIONED = " + Secure.getString(getContentResolver(), Secure.DEVICE_PROVISIONED));
		Log.d("reavelv", "ENABLED_ACCESSIBILITY_SERVICES = " + Secure.getString(getContentResolver(), Secure.ENABLED_ACCESSIBILITY_SERVICES));
		Log.d("reavelv", "ENABLED_INPUT_METHODS = " + Secure.getString(getContentResolver(), Secure.ENABLED_INPUT_METHODS));

		Log.d("reavelv", "HTTP_PROXY = " + Secure.getString(getContentResolver(), Secure.HTTP_PROXY));
		Log.d("reavelv", "INSTALL_NON_MARKET_APPS = " + Secure.getString(getContentResolver(), Secure.INSTALL_NON_MARKET_APPS));
		Log.d("reavelv", "LOCATION_PROVIDERS_ALLOWED = " + Secure.getString(getContentResolver(), Secure.LOCATION_PROVIDERS_ALLOWED));
		Log.d("reavelv", "LOCK_PATTERN_ENABLED = " + Secure.getString(getContentResolver(), Secure.LOCK_PATTERN_ENABLED));
		Log.d("reavelv", "LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED = " + Secure.getString(getContentResolver(), Secure.LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED));
		Log.d("reavelv", "LOCK_PATTERN_VISIBLE = " + Secure.getString(getContentResolver(), Secure.LOCK_PATTERN_VISIBLE));

		Log.d("reavelv", "LOGGING_ID = " + Secure.getString(getContentResolver(), Secure.LOGGING_ID));
		Log.d("reavelv", "NETWORK_PREFERENCE = " + Secure.getString(getContentResolver(), Secure.NETWORK_PREFERENCE));
		Log.d("reavelv", "PARENTAL_CONTROL_ENABLED = " + Secure.getString(getContentResolver(), Secure.PARENTAL_CONTROL_ENABLED));
		Log.d("reavelv", "PARENTAL_CONTROL_LAST_UPDATE = " + Secure.getString(getContentResolver(), Secure.PARENTAL_CONTROL_LAST_UPDATE));
		Log.d("reavelv", "SETTINGS_CLASSNAME = " + Secure.getString(getContentResolver(), Secure.SETTINGS_CLASSNAME));
		Log.d("reavelv", "SYS_PROP_SETTING_VERSION = " + Secure.getString(getContentResolver(), Secure.SYS_PROP_SETTING_VERSION));
		Log.d("reavelv", "TTS_DEFAULT_COUNTRY = " + Secure.getString(getContentResolver(), Secure.TTS_DEFAULT_COUNTRY));
		Log.d("reavelv", "TTS_DEFAULT_LANG = " + Secure.getString(getContentResolver(), Secure.TTS_DEFAULT_LANG));
		Log.d("reavelv", "TTS_DEFAULT_PITCH = " + Secure.getString(getContentResolver(), Secure.TTS_DEFAULT_PITCH));
		Log.d("reavelv", "TTS_DEFAULT_RATE = " + Secure.getString(getContentResolver(), Secure.TTS_DEFAULT_RATE));
		Log.d("reavelv", "TTS_DEFAULT_SYNTH = " + Secure.getString(getContentResolver(), Secure.TTS_DEFAULT_SYNTH));
		Log.d("reavelv", "TTS_DEFAULT_VARIANT = " + Secure.getString(getContentResolver(), Secure.TTS_DEFAULT_VARIANT));
		Log.d("reavelv", "TTS_ENABLED_PLUGINS = " + Secure.getString(getContentResolver(), Secure.TTS_ENABLED_PLUGINS));
		Log.d("reavelv", "TTS_USE_DEFAULTS = " + Secure.getString(getContentResolver(), Secure.TTS_USE_DEFAULTS));
		Log.d("reavelv", "USB_MASS_STORAGE_ENABLED = " + Secure.getString(getContentResolver(), Secure.USB_MASS_STORAGE_ENABLED));
		Log.d("reavelv", "USE_GOOGLE_MAIL = " + Secure.getString(getContentResolver(), Secure.USE_GOOGLE_MAIL));
		
		Log.d("reavelv", "WIFI_MAX_DHCP_RETRY_COUNT = " + Secure.getString(getContentResolver(), Secure.WIFI_MAX_DHCP_RETRY_COUNT));
		Log.d("reavelv", "WIFI_MOBILE_DATA_TRANSITION_WAKELOCK_TIMEOUT_MS = " + Secure.getString(getContentResolver(), Secure.WIFI_MOBILE_DATA_TRANSITION_WAKELOCK_TIMEOUT_MS));
		Log.d("reavelv", "WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON = " + Secure.getString(getContentResolver(), Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON));
		Log.d("reavelv", "WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY = " + Secure.getString(getContentResolver(), Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY));
		Log.d("reavelv", "WIFI_NUM_OPEN_NETWORKS_KEPT = " + Secure.getString(getContentResolver(), Secure.WIFI_NUM_OPEN_NETWORKS_KEPT));
		Log.d("reavelv", "WIFI_ON = " + Secure.getString(getContentResolver(), Secure.WIFI_ON));
		Log.d("reavelv", "WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE = " + Secure.getString(getContentResolver(), Secure.WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE));
		*/
		/*
		Log.d("reavelv", "SCREEN_BRIGHTNESS = " + 
				android.provider.Settings.System.getString(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS));
		Log.d("reavelv", "ACCELEROMETER_ROTATION = " + 
				android.provider.Settings.System.getString(getContentResolver(), android.provider.Settings.System.ACCELEROMETER_ROTATION));
		Log.d("reavelv", "ANDROID_ID = " + 
				android.provider.Settings.System.getString(getContentResolver(), android.provider.Settings.System.ANDROID_ID));
		Log.d("reavelv", "APPEND_FOR_LAST_AUDIBLE = " + 
				android.provider.Settings.System.getString(getContentResolver(), android.provider.Settings.System.APPEND_FOR_LAST_AUDIBLE));
		Log.d("reavelv", "AUTO_TIME = " + 
				android.provider.Settings.System.getString(getContentResolver(), android.provider.Settings.System.AUTO_TIME));
		Log.d("reavelv", "BLUETOOTH_ON = " + 
				android.provider.Settings.System.getString(getContentResolver(), android.provider.Settings.System.BLUETOOTH_ON));
		Log.d("reavelv", "BLUETOOTH_DISCOVERABILITY = " + 
				android.provider.Settings.System.getString(getContentResolver(), android.provider.Settings.System.BLUETOOTH_DISCOVERABILITY));
		Log.d("reavelv", "BLUETOOTH_DISCOVERABILITY_TIMEOUT = " + 
				android.provider.Settings.System.getString(getContentResolver(), android.provider.Settings.System.BLUETOOTH_DISCOVERABILITY_TIMEOUT));
		Log.d("reavelv", "DATE_FORMAT = " + 
				android.provider.Settings.System.getString(getContentResolver(), android.provider.Settings.System.DATE_FORMAT));
		Log.d("reavelv", "DEBUG_APP = " + 
				android.provider.Settings.System.getString(getContentResolver(), android.provider.Settings.System.DEBUG_APP));
		Log.d("reavelv", "DEVICE_PROVISIONED = " + 
				android.provider.Settings.System.getString(getContentResolver(), android.provider.Settings.System.DEVICE_PROVISIONED));
		Log.d("reavelv", "DIM_SCREEN = " + 
				android.provider.Settings.System.getString(getContentResolver(), android.provider.Settings.System.DIM_SCREEN));
		Log.d("reavelv", "DTMF_TONE_WHEN_DIALING = " + 
				android.provider.Settings.System.getString(getContentResolver(), android.provider.Settings.System.DTMF_TONE_WHEN_DIALING));
		*/
		//Vibrator vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); 
		//vibe.vibrate(3000);
		/*
		AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
		Log.d("reavelv", "EXTRA_RINGER_MODE" + am.getParameters(AudioManager.EXTRA_RINGER_MODE));
		*/
		//PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
		//DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
		
		//List<ComponentName> adminslist = (List<ComponentName>) dpm.getActiveAdmins();
		//Log.d("reavelv", "adminslist = " + adminslist);
		
		//UiModeManager uim = (UiModeManager)getSystemService(Context.UI_MODE_SERVICE);
		
//		Log.d("reavelv", "===============================================================");
//		WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
//		if(!wm.isWifiEnabled()){
//			//====================================================================
//			// Wifi On Setting
//			Log.e("reavelv", "wm.setWifiEnabled = " + wm.setWifiEnabled(true));
//			//====================================================================
//		}
//		getLocaleFolder("/MWSAutoSync/smalltext.txt");
		
//		Date date1 = new Date(SystemClock.currentThreadTimeMillis());
//		Date date2 = new Date(SystemClock.currentThreadTimeMillis());
//
//		WifiInfo wiInfo = wm.getConnectionInfo();
//		
//		while(!SupplicantState.COMPLETED.equals(wiInfo.getSupplicantState())&& 
//				!SupplicantState.UNINITIALIZED.equals(wiInfo.getSupplicantState())){
//
//			Log.w("reavelv", "SupplicantState() = " + wiInfo.getSupplicantState());
//			date2 = new Date(SystemClock.currentThreadTimeMillis());
//			if(date1.getTime() + 100 < date2.getTime()){
//				Log.e("reavelv", "wifi timeout");
//				break;
//			}
//		}
//		
//		
//		Log.d("reavelv", "wiInfo = " + wiInfo);
//		Log.d("reavelv", "getBSSID = " + wiInfo.getBSSID());	// AP Mac Address
//		Log.d("reavelv", "getSSID = " + wiInfo.getSSID());		// AP Name
//		
//		/**
//		 * wiInfo = SSID: Challenge14, BSSID: 00:26:66:6a:56:08, MAC: 00:12:47:F1:9E:0B, Supplicant state: UNINITIALIZED, RSSI: -200, Link speed: 39, Net ID: 12
//		 * getBSSID = 00:26:66:6a:56:08
//		 * getSSID = Challenge14
//		 */
//		
//		Log.d("reavelv", "===============================================================");
		
//		ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_SYSTEM, 50);
		//tg.startTone(ToneGenerator.TONE_CDMA_HIGH_L, 100);
		
		
		/*
		Log.d("reavelv", "getIpAddress1 = " + wiInfo.getIpAddress());
		//Log.d("reavelv", "getIpAddress2 = " + toHexString(wiInfo.getIpAddress()));
		Log.d("reavelv", "getLinkSpeed = " + wiInfo.getLinkSpeed());
		Log.d("reavelv", "getMacAddress = " + wiInfo.getMacAddress());
		Log.d("reavelv", "getNetworkId = " + wiInfo.getNetworkId());
		Log.d("reavelv", "getRssi = " + wiInfo.getRssi());
		Log.d("reavelv", "getBSSID = " + wiInfo.getBSSID());
		Log.d("reavelv", "getSSID = " + wiInfo.getSSID());
		Log.d("reavelv", "getHiddenSSID = " + wiInfo.getHiddenSSID());
		SupplicantState wi = wiInfo.getSupplicantState();
		Log.d("reavelv", "SupplicantState name = " + wi.name());
		Log.d("reavelv", "SupplicantState ordinal = " + wi.ordinal());
		DetailedState ds = WifiInfo.getDetailedStateOf(wiInfo.getSupplicantState());
		Log.d("reavelv", "SupplicantState name = " + ds.name());
		Log.d("reavelv", "SupplicantState ordinal = " + ds.ordinal());
		*/
		/*
		String curSSID = wiInfo.getSSID(), wantSSID = null;//"Challenge14";//"DS_DEV2";
		if(wiInfo.getSSID() == null){
			curSSID = "Challenge14";
		}
		if(curSSID.equals("Challenge14"))
			wantSSID = "DS_DEV2";
		else// if(curSSID.equals("DS_DEV2"))
			wantSSID = "Challenge14";
		
		List<ScanResult> WifiScanList = wm.getScanResults();
		WifiConfiguration wfc = new WifiConfiguration();
		int maxPrior = -1;
//		
//		for(ScanResult sr : WifiScanList){
//			Log.d("reavelv", "===============================================================");
//			Log.d("reavelv", "===============================================================");
//			Log.i("reavelv", "capabilities - " + sr.capabilities);
//			Log.i("reavelv", "BSSID - " + sr.BSSID);
//			Log.i("reavelv", "frequency - " + sr.frequency);
//			Log.i("reavelv", "level - " + sr.level);
//			Log.i("reavelv", "SSID - " + sr.SSID);
//			Log.i("reavelv", "describeContents - " + sr.describeContents());
//			Log.d("reavelv", "===============================================================");
//			Log.d("reavelv", "===============================================================");
////			 http://iriyakana.tistory.com/4
//			if(curSSID.equals("Challenge14")){
//				if(sr.SSID.equals("DS_DEV2")){
//					wfc.BSSID = sr.BSSID;
//					wfc.SSID = sr.SSID;
//					wfc.hiddenSSID = false;
//					setupSecurity(wfc, WEP, "06705");
//					
//				}
//			}
//			else if(curSSID.equals("DS_DEV2")){
//				if(sr.SSID.equals("Challenge14")){
//					wfc.BSSID = sr.BSSID;
//					wfc.SSID = sr.SSID;
//					wfc.hiddenSSID = false;
//					setupSecurity(wfc, WPA, "00006705");
//					
//				}
//			}
//			
//			
//			
//			
//		}
		
		List<WifiConfiguration> WifiConList = wm.getConfiguredNetworks();
		Log.e("reavelv", "init networkId - " + wfc.networkId);
		
		int curPrior = -1, wantPrior = -1, tmp = -1;
		Log.i("reavelv", "curSSID - " + curSSID);
		Log.i("reavelv", "wantSSID - " + wantSSID);
		boolean isSaved = false;
		if(!curSSID.equals(wantSSID)){
			Log.i("reavelv", "???");
			for(int i = 0 ; i < WifiConList.size() ; i++){
//				Log.d("reavelv", "===============================================================");
//				Log.d("reavelv", "===============================================================");
//				Log.i("reavelv", "priority - " + wcl.priority);
//				Log.i("reavelv", "BSSID - " + wcl.BSSID);
//				Log.i("reavelv", "preSharedKey - " + wcl.preSharedKey);
//				Log.i("reavelv", "status - " + wcl.status);
//				Log.i("reavelv", "SSID - " + wcl.SSID);
//				Log.i("reavelv", "describeContents - " + wcl.describeContents());
//				Log.i("reavelv", "wepTxKeyIndex - " + wcl.wepTxKeyIndex);
//				Log.i("reavelv", "allowedAuthAlgorithms - " + wcl.allowedAuthAlgorithms);
//				Log.d("reavelv", "===============================================================");
//				Log.d("reavelv", "===============================================================");
				

				Log.i("reavelv", "priority - " + WifiConList.get(i).priority);
//				Log.i("reavelv", "BSSID - " + WifiConList.get(i).BSSID);
				Log.i("reavelv", "SSID - " + WifiConList.get(i).SSID);
				Log.i("reavelv", "networkId - " + WifiConList.get(i).networkId);
				
				if(WifiConList.get(i).SSID == null){
					Log.e("reavelv", "priority - " + WifiConList.get(i).priority);
					Log.e("reavelv", "BSSID - " + WifiConList.get(i).BSSID);
					Log.e("reavelv", "preSharedKey - " + WifiConList.get(i).preSharedKey);
					Log.e("reavelv", "status - " + WifiConList.get(i).status);
					Log.e("reavelv", "SSID - " + WifiConList.get(i).SSID);
					Log.e("reavelv", "describeContents - " + WifiConList.get(i).describeContents());
					Log.e("reavelv", "wepTxKeyIndex - " + WifiConList.get(i).wepTxKeyIndex);
					Log.e("reavelv", "networkId - " + WifiConList.get(i).networkId);
					Log.e("reavelv", "wm.removeNetwork(" + WifiConList.get(i).networkId + " - " 
							+ wm.removeNetwork(WifiConList.get(i).networkId));
					
					continue;
				}
				
				if(maxPrior < WifiConList.get(i).priority){
					maxPrior = WifiConList.get(i).priority;
				}
				
				if(curSSID.equals("Challenge14")){
					if(WifiConList.get(i).SSID.equals("\"" + wantSSID + "\"")){
						wfc = WifiConList.get(i);
						tmp = i;

						Log.w("reavelv", "priority - " + WifiConList.get(i).priority);
						Log.w("reavelv", "BSSID - " + WifiConList.get(i).BSSID);
						Log.w("reavelv", "preSharedKey - " + WifiConList.get(i).preSharedKey);
						Log.w("reavelv", "status - " + WifiConList.get(i).status);
						Log.w("reavelv", "SSID - " + WifiConList.get(i).SSID);
						Log.w("reavelv", "describeContents - " + WifiConList.get(i).describeContents());
						Log.w("reavelv", "wepTxKeyIndex - " + WifiConList.get(i).wepTxKeyIndex);
						Log.w("reavelv", "networkId - " + WifiConList.get(i).networkId);
						
						Log.e("reavelv", "allowedAuthAlgorithms - " + WifiConList.get(i).allowedAuthAlgorithms);
						Log.e("reavelv", "allowedGroupCiphers - " + WifiConList.get(i).allowedGroupCiphers);
						Log.e("reavelv", "allowedKeyManagement - " + WifiConList.get(i).allowedKeyManagement);
						Log.e("reavelv", "allowedPairwiseCiphers - " + WifiConList.get(i).allowedPairwiseCiphers);
						Log.e("reavelv", "allowedProtocols - " + WifiConList.get(i).allowedProtocols);
						
						BitSet bs = WifiConList.get(i).allowedAuthAlgorithms;
						
						
						continue;
					}
					if(WifiConList.get(i).SSID.equals("\"" + "DS_DEV2" + "\"")){
						setupSecurity(wfc, WEP, "06705");
						wfc.BSSID = WifiConList.get(i).BSSID;
						wfc.SSID = WifiConList.get(i).SSID;
						wfc.hiddenSSID = false;
						
					}
				}
				else{// if(curSSID.equals("DS_DEV2")){
					if(WifiConList.get(i).SSID.equals("\"" + wantSSID + "\"")){
						wfc = WifiConList.get(i);
						tmp = i;

						Log.w("reavelv", "priority - " + WifiConList.get(i).priority);
						Log.w("reavelv", "BSSID - " + WifiConList.get(i).BSSID);
						Log.w("reavelv", "preSharedKey - " + WifiConList.get(i).preSharedKey);
						Log.w("reavelv", "status - " + WifiConList.get(i).status);
						Log.w("reavelv", "SSID - " + WifiConList.get(i).SSID);
						Log.w("reavelv", "describeContents - " + WifiConList.get(i).describeContents());
						Log.w("reavelv", "wepTxKeyIndex - " + WifiConList.get(i).wepTxKeyIndex);
						Log.w("reavelv", "networkId - " + WifiConList.get(i).networkId);
						
						Log.e("reavelv", "allowedAuthAlgorithms - " + WifiConList.get(i).allowedAuthAlgorithms);
						Log.e("reavelv", "allowedGroupCiphers - " + WifiConList.get(i).allowedGroupCiphers);
						Log.e("reavelv", "allowedKeyManagement - " + WifiConList.get(i).allowedKeyManagement);
						Log.e("reavelv", "allowedPairwiseCiphers - " + WifiConList.get(i).allowedPairwiseCiphers);
						Log.e("reavelv", "allowedProtocols - " + WifiConList.get(i).allowedProtocols);
						BitSet bs = WifiConList.get(i).allowedAuthAlgorithms;
						continue;
					}
					if(WifiConList.get(i).SSID.equals("\"" + "Challenge14" + "\"")){
						setupSecurity(wfc, WPA, "00006705");
						wfc.BSSID = WifiConList.get(i).BSSID;
						wfc.SSID = WifiConList.get(i).SSID;
						wfc.hiddenSSID = false;
						
					}
				}
				
			}
			if(!isSaved)
				wfc.priority = maxPrior + 1;
			
		}
		
		
		
		Log.i("reavelv", "disconnect() - " + wm.disconnect());
		

		Log.e("reavelv", "================set wfc====================");
		Log.e("reavelv", "priority - " + wfc.priority);
		Log.e("reavelv", "BSSID - " + wfc.BSSID);
		Log.e("reavelv", "preSharedKey - " + wfc.preSharedKey);
		Log.e("reavelv", "status - " + wfc.status);
		Log.e("reavelv", "SSID - " + wfc.SSID);
		Log.e("reavelv", "describeContents - " + wfc.describeContents());
		Log.e("reavelv", "wepTxKeyIndex - " + wfc.wepTxKeyIndex);
		Log.e("reavelv", "networkId - " + wfc.networkId);
		
//		int networkId = wm.addNetwork(wfc);
//		
//		Log.i("reavelv", "networkId - " + networkId);
//		if(networkId != -1){
//			Log.d("d","NetworkID : "+networkId);
//			if(!wm.enableNetwork(networkId, true)){
//				networkId = -1;
//			}
//		}
		if(tmp != -1)
			Log.d("reavelv", "updateNetwork - " + wm.updateNetwork(WifiConList.get(tmp)));
//						getConfiguredNetworks()
		
		


		
/*  		
 			DATA_DISCONNECTED
			DATA_CONNECTING
			DATA_CONNECTED
			DATA_SUSPENDED 
		 
        TelephonyManager tm = (TelephonyManager) getSystemService(this.TELEPHONY_SERVICE);
		Log.d("reavelv", "getDataState = " + tm.getDataState());
		Log.d("reavelv", "getLine1Number = " + tm.getLine1Number());
        */
		
//		SensorManager sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
//		
//		List<Sensor> smList = sm.getSensorList(Sensor.TYPE_ALL);
//		Sensor.TYPE_ACCELEROMETER	1
//		Sensor.TYPE_MAGNETIC_FIELD	2
//		Sensor.TYPE_ORIENTATION		3
//		Sensor.TYPE_GYROSCOPE		4
//		Sensor.TYPE_LIGHT			5
//		Sensor.TYPE_PRESSURE		6
//		Sensor.TYPE_TEMPERATURE		7
//		Sensor.TYPE_PROXIMITY		8
		
		/*
		for(int i = 0 ; i < smList.size() ; i++){
			Log.d("reavelv", "getName = " + smList.get(i).getName());
			Log.d("reavelv", "getPower = " + smList.get(i).getPower());
			Log.d("reavelv", "getMaximumRange = " + smList.get(i).getMaximumRange());
			Log.d("reavelv", "getType = " + smList.get(i).getType());
			Log.d("reavelv", "getVendor = " + smList.get(i).getVendor());
			Log.d("reavelv", "getVersion = " + smList.get(i).getVersion());
			Log.d("reavelv", "====================================");
		}
		*/
		/*
		for(int i = 0 ; i < 7 ; i++){
			Sensor ss = sm.getDefaultSensor(i+1);
			if(ss != null){
				Log.d("reavelv", "getName = " + ss.getName());
				Log.d("reavelv", "getPower = " + ss.getPower());
				Log.d("reavelv", "getMaximumRange = " + ss.getMaximumRange());
				Log.d("reavelv", "getType = " + ss.getType());
				Log.d("reavelv", "getVendor = " + ss.getVendor());
				Log.d("reavelv", "getVersion = " + ss.getVersion());
				Log.d("reavelv", "====================================");
			}
		}
		*/
		/*
		ClipboardManager cm = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
		cm.getText();
		cm.setText("sss");
		*/
		/*
		AccessibilityManager am = (AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE);
		List<ServiceInfo> serviceList = am.getAccessibilityServiceList();

		for(int i = 0 ; i < serviceList.size() ; i++){
			Log.d("reavelv", "name = " + serviceList.get(i).name);
			Log.d("reavelv", "packageName = " + serviceList.get(i).packageName);
			Log.d("reavelv", "permission = " + serviceList.get(i).permission);
			Log.d("reavelv", "processName = " + serviceList.get(i).processName);
			Log.d("reavelv", "====================================");
		}
		*/
		/*
		int brightness = 180;
		
		Log.d("reavelv", "SCREEN_BRIGHTNESS = " + 
				android.provider.Settings.System.getString(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS));
		
		android.provider.Settings.System.putInt(getContentResolver(), 
				android.provider.Settings.System.SCREEN_BRIGHTNESS, brightness);
		
		Log.d("reavelv", "SCREEN_BRIGHTNESS = " + 
				android.provider.Settings.System.getString(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS));
		
		Window window = getWindow();
		if(brightness == 0)
			window.getAttributes().screenBrightness = 0.05f;
		else{
			Log.d("reavelv", "brightness = " + (float)((float)brightness / 255));
			window.getAttributes().screenBrightness = (float)((float)brightness / 255);
		}
		*/
		
//		startActivity(new Intent(this, testDialLogActivity.class).putExtra("brightness", 50).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
		
		
		//finish();
		/*
		
        // long x = Long.parseLong(userId, 16);
        TelephonyManager tm = (TelephonyManager) getSystemService(this.TELEPHONY_SERVICE);
        Log.d("reavelv", "getSubscriberId() = " + tm.getSubscriberId());
        Log.d("reavelv", "getDeviceId() = " + tm.getDeviceId());
        Log.d("reavelv", "getSimOperator() = " + tm.getSimOperator());
        Log.d("reavelv", "getDeviceSoftwareVersion() = " + tm.getDeviceSoftwareVersion());
        Log.d("reavelv", "getLine1Number() = " + tm.getLine1Number());
        Log.d("reavelv", "getNetworkOperator() = " + tm.getNetworkOperator());
        Log.d("reavelv", "getNetworkOperatorName() = " + tm.getNetworkOperatorName());
*/
		/*
    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
    	
        Log.d("reavelv", "BOARD: " + Build.BOARD);
        Log.d("reavelv", "BRAND: " + Build.BRAND);
        Log.d("reavelv", "CPU_ABI: " + Build.CPU_ABI);
        Log.d("reavelv", "CPU_ABI2: " + Build.CPU_ABI2);
        Log.d("reavelv", "DEVICE: " + Build.DEVICE);
        Log.d("reavelv", "DISPLAY: " + Build.DISPLAY);
        Log.d("reavelv", "FINGERPRINT: " + Build.FINGERPRINT);
        Log.d("reavelv", "HARDWARE: " + Build.HARDWARE);
        Log.d("reavelv", "HOST: " + Build.HOST);
        Log.d("reavelv", "ID: " + Build.ID);
        Log.d("reavelv", "MANUFACTURER: " + Build.MANUFACTURER);
        Log.d("reavelv", "MODEL: " + Build.MODEL);
        Log.d("reavelv", "PRODUCT: " + Build.PRODUCT);
        Log.d("reavelv", "TAGS: " + Build.TAGS);
        Log.d("reavelv", "TIME: " + Build.TIME);
        Log.d("reavelv", "TYPE: " + Build.TYPE);
        Log.d("reavelv", "USER: " + Build.USER);
        
        Log.d("reavelv", "BOOTLOADER: " + Build.BOOTLOADER);
        Log.d("reavelv", "RADIO: " + Build.RADIO);

        Log.d("reavelv", "VERSION.CODENAME: " + Build.VERSION.CODENAME);
        Log.d("reavelv", "VERSION.INCREMENTAL: " + Build.VERSION.INCREMENTAL);
        Log.d("reavelv", "VERSION.RELEASE: " + Build.VERSION.RELEASE);
        Log.d("reavelv", "VERSION.CODENAME: " + Build.VERSION.SDK);
        Log.d("reavelv", "VERSION.SDK_INT: " + Build.VERSION.SDK_INT);
        
        Date buildTime = new Date(Build.TIME);
        Log.i("reavelv", "buildTime " + (buildTime.getYear() + 1900) + "/"
        		+ buildTime.getMonth() + "/" + buildTime.getDate() + " - " 
        		+ buildTime.getHours() + ":" + buildTime.getMinutes() +
				":" + buildTime.getSeconds());
        
/*
        Log.d("reavelv", "VERSION_CODES.BASE: " + Build.VERSION_CODES.BASE);
        Log.d("reavelv", "VERSION_CODES.BASE_1_1: " + Build.VERSION_CODES.BASE_1_1);
        Log.d("reavelv", "VERSION_CODES.FROYO: " + Build.VERSION_CODES.FROYO);
        Log.d("reavelv", "VERSION_CODES.CUR_DEVELOPMENT: " + Build.VERSION_CODES.CUR_DEVELOPMENT);
        /*
        Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(intent, 1337);
        */
		
		//List<PackageInfo> packages = getPackageManager().getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
		/*
		ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
		List<RunningTaskInfo> Info = am.getRunningTasks(50);
		Log.d("reavelv", "Info.size = " + Info.size());
		for(int i = 0 ; i < Info.size() ; i++){
			Log.d("reavelv", "topActivity = " + Info.get(i).topActivity);
		}
		*/
        
        
		//packages.get(mmsid).applicationInfo.packageName;
        
        /*
        JSONObject js = new JSONObject();
		Log.d("reavelv", "start test");
        try {
			js.put("test1", "test1 \n test1");
			js.accumulate("test2", "test2 \n test2");
			Log.d("reavelv", "test1 = " + js.toString());
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		{ MediaStore.Images.Media.EXTERNAL_CONTENT_URI, MediaStore.Images.Media.INTERNAL_CONTENT_URI };
        }
        else if (TYPE_AUDIO.equals(mediatype))
        {
            return new Uri[]
            { MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, MediaStore.Audio.Media.INTERNAL_CONTENT_URI };
        }
        else if (TYPE_VIDEO.equals(mediatype))
        {
            return new Uri[]
            { MediaStore.Video.Media.EXTERNAL_CONTENT_URI, MediaStore.Video.Media.INTERNAL_CONTENT_URI };
		*/
		
		
    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
    	Log.d("reavelv", "INTERNAL_CONTENT_URI = " + MediaStore.Audio.Media.INTERNAL_CONTENT_URI);  
    	
        /*
        Cursor c = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null, null, null);
        
        int x = 0;
        /*
    	Log.d("reavelv", "" + c.getCount());   
    	for(int i = 0 ; i < c.getColumnNames().length ; i++){
    		Log.d("reavelv", "" + c.getColumnNames()[i]); 
    	}
    	if(c.moveToFirst()){
    		while(true){
	        	Log.d("reavelv", "_id = " + c.getInt(c.getColumnIndex("_id")));   
	        	Log.d("reavelv", "_data = " + c.getString(c.getColumnIndex("_data")));  
	        	
	        	x++;
	        	c.moveToNext();
	        	if(x == c.getCount()){
	            	Log.d("reavelv", "thread end ");           		
	        		break;
	        	}
    		}
    	}
    	*/
        
        
        /*
    	c = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null, null, null);
    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
        
		
        x = 0;
    	Log.d("reavelv", "" + c.getCount());   
    	for(int i = 0 ; i < c.getColumnNames().length ; i++){
    		//Log.d("reavelv", "" + c.getColumnNames()[i]); 
    	}
    	
    	if(c.moveToFirst()){
    		while(true){
//	        	Log.d("reavelv", "_id = " + c.getInt(c.getColumnIndex("_id")));   
//	        	Log.d("reavelv", "_data = " + c.getString(c.getColumnIndex("_data")));  
	        	
    			for(int i = 0 ; i < c.getColumnNames().length ; i++){
    	    		//Log.d("reavelv", "" + c.getColumnNames()[i]); 
    	    		Log.d("reavelv", c.getColumnNames()[i] + " - " + c.getString(c.getColumnIndex(c.getColumnNames()[i])));
    	    	}
    			
	        	x++;
	        	c.moveToNext();
	        	if(x == c.getCount() || x > 3){
	            	Log.d("reavelv", "thread end ");           		
	        		break;
	        	}
    		}
    	}

    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
    	
        /*
		Log.d("reavelv", "test2 = ");
		
		Log.d("reavelv", "start test");
		
        
        Cursor c = getContentResolver().query(contentUri, null, null, null, null);
        
        int x = 0;
    	Log.d("reavelv", "" + c.getCount());   
    	for(int i = 0 ; i < c.getColumnNames().length ; i++){
    		Log.d("reavelv", "" + c.getColumnNames()[i]); 
    	}
    	if(c.moveToFirst()){
    		while(true){
	        	Log.d("reavelv", "_id = " + c.getInt(c.getColumnIndex("_id")));   
	        	Log.d("reavelv", "snippet = " + c.getString(c.getColumnIndex("snippet")));  
	        	x++;
	        	c.moveToNext();
	        	if(x == c.getCount()){
	            	Log.d("reavelv", "thread end ");           		
	        		break;
	        	}
    		}
    	}
    	
    	c.close();
    	c = null;
    	c = getContentResolver().query(Uri.parse("content://sms/sent"), null, null , null, null);

    	Log.d("reavelv", "inbox start");    
    	Log.d("reavelv", "" + c.getCount());   
    	for(int i = 0 ; i < c.getColumnNames().length ; i++){
    		Log.d("reavelv", "" + c.getColumnNames()[i]); 
    	}
    	Log.d("reavelv", "end ");   
        x = 0;
    	if(c.moveToFirst()){
    		while(true){
	        	Log.d("reavelv", "address = " + c.getString(c.getColumnIndex("address")));  
	        	Log.d("reavelv", "body = " + c.getString(c.getColumnIndex("body")));    
	        	x++;
	        	c.moveToNext();
	        	if(x == c.getCount()){
	            	Log.d("reavelv", "inbox end ");           		
	        		break;
	        	}
    		}
    	}
    	*/
        
        /*
        int token;
        for(int i = 0 ; i < 5 ; i++){
        	token= new Random().nextInt(8999) + 1000;
            Log.d("reavelv", "token " + i + " = " + token);
        }
        */
        
        /*
        String testSTR = "1;0;55;23;6;77;0;";
        int x = testSTR.indexOf(";", 0), s = 0;;

        Log.d("reavelv", "testSTR.indexOf(, x) - " + testSTR.indexOf(";", x));
        Log.d("reavelv", "testSTR0 - " + testSTR.substring(s, testSTR.indexOf(";", x)));
        
        s = x + 1;
        x = testSTR.indexOf(";", x + 1);

        Log.d("reavelv", "testSTR.indexOf(, x) - " + testSTR.indexOf(";", x));
        Log.d("reavelv", "testSTR1 - " + testSTR.substring(s, testSTR.indexOf(";", x)));

        s = x + 1;
        x = testSTR.indexOf(";", x + 1);

        Log.d("reavelv", "testSTR.indexOf(, x) - " + testSTR.indexOf(";", x));
        Log.d("reavelv", "testSTR2 - " + testSTR.substring(s, testSTR.indexOf(";", x)));

        s = x + 1;
        x = testSTR.indexOf(";", x + 1);

        Log.d("reavelv", "testSTR.indexOf(, x) - " + testSTR.indexOf(";", x));
        Log.d("reavelv", "testSTR3 - " + testSTR.substring(s, testSTR.indexOf(";", x)));

        s = x + 1;
        x = testSTR.indexOf(";", x + 1);

        Log.d("reavelv", "testSTR.indexOf(, x) - " + testSTR.indexOf(";", x));
        Log.d("reavelv", "testSTR4 - " + testSTR.substring(s, testSTR.indexOf(";", x)));

        s = x + 1;
        x = testSTR.indexOf(";", x + 1);

        Log.d("reavelv", "testSTR.indexOf(, x) - " + testSTR.indexOf(";", x));
        Log.d("reavelv", "testSTR5 - " + testSTR.substring(s, testSTR.indexOf(";", x)));

        s = x + 1;
        x = testSTR.indexOf(";", x + 1);

        Log.d("reavelv", "testSTR.indexOf(, x) - " + testSTR.indexOf(";", x));
        Log.d("reavelv", "testSTR6 - " + testSTR.substring(s, testSTR.indexOf(";", x)));
        */
        
        /*
        ContentValues contactValue = new ContentValues();
		
		contactValue.put(RawContacts.VERSION, 2);
		contactValue.put("contact_in_visible_group", 1);
		
		Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI, contactValue);
		int rawContactId = (int) ContentUris.parseId(rawContactUri);
        
		contactValue.clear();
		contactValue.put(Contacts.IN_VISIBLE_GROUP, 1);
		Uri ContactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, rawContactId);
		getContentResolver().update(ContactUri, contactValue, null, null);

		//displayname input
		contactValue.clear();
		
		contactValue.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
		contactValue.put("raw_contact_id", rawContactId);
		contactValue.put(StructuredName.DISPLAY_NAME, "test");
		contactValue.put(Data.DATA2, "testname");
		getContentResolver().insert(Data.CONTENT_URI, contactValue);
		*/
        m_Context = this;
        m_battLevel = -1;
        
        
        //Log.d("reavelv", "context1 : " + getApplicationContext());
        


        /*
        new Thread(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				
				Runnable runableobj = new Runnable() {
					
					@Override
					public void run() {
						// TODO Auto-generated method stub
						//m_Context.finish();
						Log.d("reavelv", "runableobj");

						
						//if(m_battLevel == -1)
							//m_Handler.postAtTime(this, 10);
					}
				};

				Log.d("reavelv", "Thread");
				m_betterybreceiver = new BatteryStatusReceiver();
		        IntentFilter ift = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
		        ift.addAction("test.test.test.test.test");
		        registerReceiver(m_betterybreceiver, ift);
				m_Handler.post(runableobj);
			}
		}).start();
        
    	Log.d("reavelv", "m_battLevel = " + m_battLevel);
    	Log.d("reavelv", "m_battLevel = " + m_battLevel);
    	Log.d("reavelv", "m_battLevel = " + m_battLevel);
    	Log.d("reavelv", "m_battLevel = " + m_battLevel);
    	Log.d("reavelv", "m_battLevel = " + m_battLevel);
    	Log.d("reavelv", "m_battLevel = " + m_battLevel);
    	Log.d("reavelv", "m_battLevel = " + m_battLevel);
    	Log.d("reavelv", "m_battLevel = " + m_battLevel);
    	Log.d("reavelv", "m_battLevel = " + m_battLevel);
    	Log.d("reavelv", "m_battLevel = " + m_battLevel);
    	*/
        
        
        
        
        /*
        while(m_battLevel == -1){
        	Log.d("reavelv", "m_battLevel = " + m_battLevel);
        }
        */
//		readAvailMem();
        
        
        
        Display display = ((WindowManager) getBaseContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();	// 占쎈떱�앾옙�덉굲 占쎌쥙猷욑옙�용쐻占쎌늿�뺧옙醫롫짗占쏙옙占쎌쥙猷욑옙�용쐻占쎌늿�뺧옙醫롫짗占쎌눨�앾옙�덉굲
        int width = display.getWidth();
        int height = display.getHeight();
        Log.d("reavelv", "width : " + width);
        Log.d("reavelv", "height : " + height);
//        Log.d("reavelv", "Build.VERSION.RELEASE = " + Build.VERSION.RELEASE);
//        for(int z = 0 ; z <  Build.VERSION.RELEASE.length() ; z++){
//        	Log.d("reavelv", "Build.VERSION.RELEASE" + z + " = " + Build.VERSION.RELEASE.charAt(z));
//        }
//        String CalendarContentVersion;
//        if(Integer.parseInt(Build.VERSION.RELEASE.charAt(0) + "") == 1)
//			CalendarContentVersion = "content://calendar";// +"/events";
//		else{
//			if(Integer.parseInt(Build.VERSION.RELEASE.charAt(2) + "") <= 1)
//				CalendarContentVersion = "content://calendar";// +"/events";
//			else
//				CalendarContentVersion = "content://com.android.calendar";
//			
//		}
        
//        Cursor c = getContentResolver().query(Uri.parse(CalendarContentVersion + "/events"), null, null, null, null);
        
//        Cursor c = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
        
//        Uri SyncStateUri = ContactsContract.SyncState.CONTENT_URI;//Uri.parse("content://com.android.contacts/accounts");
        Log.d("reavelv", "MediaStore.getMediaScannerUri() = " + MediaStore.getMediaScannerUri().toString());
        Log.d("reavelv", "Video.Media.EXTERNAL_CONTENT_URI = " + Video.Media.EXTERNAL_CONTENT_URI.toString());
        
//        Cursor c = getContentResolver().query(SyncStateUri, null, null, null, null);
//        Cursor c = getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, null, null, null);
//        Cursor c = getContentResolver().query(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, null, null, null, null);
//        Cursor c = getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, null, null, null);
		
//        if(c.moveToFirst()){
//        	for(int p = 0 ; p < c.getColumnCount() ; p++){
//    			Log.d("reavelv", c.getColumnName(p));
//        	}
//        	Log.w("reavelv", "c.getColumnName() end");
//        	for(int p = 0 ; p < c.getColumnCount() ; p++){
//        		try{
//        			Log.d("reavelv", c.getColumnName(p) + " = " + c.getString(c.getColumnIndex(c.getColumnName(p))));
//        		
//        		}catch(SQLiteException e){
//        			Log.d("reavelv", e + "");
//        			Log.d("reavelv", c.getColumnName(p) + " = " + c.getBlob(c.getColumnIndex(c.getColumnName(p))));
//        		}
//        	}
//        	int z = 0;
//        	while(c.moveToNext()){
//        		for(int p = 0 ; p < c.getColumnCount() ; p++){
//        			try{
//            			Log.d("reavelv", c.getColumnName(p) + " = " + c.getString(c.getColumnIndex(c.getColumnName(p))));
//            		
//            		}catch(SQLiteException e){
//            			Log.d("reavelv", e + "");
//            			Log.d("reavelv", c.getColumnName(p) + " = " + c.getBlob(c.getColumnIndex(c.getColumnName(p))));
//            		}
//        		}
//        	}
//        }
        
//        MWSLog.i("test", "test");
//        MWSCalendars msss = new MWSCalendars();
//        ArrayList<Calendar> tmp = msss.getCalendarList(this);
//        Event tmpcalevent = null;
//        for(int xx = 0 ; xx < tmp.size() ; xx++){
//        	ArrayList<Event> tmpevent = msss.findEvents(this, tmp.get(xx));
//        	MWSLog.d("size", tmpevent.size() + "");
//        	for(Event eve : tmpevent){
//        		if(eve.getID() == 1)
//        			tmpcalevent = tmpevent.get(0);
//        		MWSLog.e("getCalendarID", eve.getCalendarID() + "");
//        		MWSLog.d("getID", eve.getID() + "");
//        		MWSLog.d("Description", eve.getDescription());
//        		time = new Date(Long.parseLong(eve.getStartTime()));
//        		MWSLog.d("getStartTime", ((int)time.getYear() + 1900) + "/" 
//        				+ ((int)time.getMonth() + 1) + "/" + time.getDate() + "-" + time.getHours());
//        		time = new Date(Long.parseLong(eve.getEndTime()));
//        		MWSLog.d("getEndTime", ((int)time.getYear() + 1900) + "/" 
//        				+ ((int)time.getMonth() + 1) + "/" + time.getDate() + "-" + time.getHours());
//        		MWSLog.d("getTitle", eve.getTitle());
//        	}
//        }
//        
//        MWSLog.e("getCalendarID", tmpcalevent.getCalendarID() + "");
//		MWSLog.d("getID", tmpcalevent.getID() + "");
//		MWSLog.d("Description", tmpcalevent.getDescription());
//		time = new Date(Long.parseLong(tmpcalevent.getStartTime()));
//		MWSLog.d("getStartTime", ((int)time.getYear() + 1900) + "/" 
//				+ ((int)time.getMonth() + 1) + "/" + time.getDate() + "-" + time.getHours());
//		time = new Date(Long.parseLong(tmpcalevent.getEndTime()));
//		MWSLog.d("getEndTime", ((int)time.getYear() + 1900) + "/" 
//				+ ((int)time.getMonth() + 1) + "/" + time.getDate() + "-" + time.getHours());
//		MWSLog.d("getTitle", tmpcalevent.getTitle());
//		
//        tmpcalevent.setDescription("aaaaaa");
//        msss.updateEvent(this, tmpcalevent);
//        tmp = msss.getCalendarList(this);
//        
//        for(int xx = 0 ; xx < tmp.size() ; xx++){
//        	ArrayList<Event> tmpevent = msss.findEvents(this, tmp.get(xx));
//        	for(Event eve : tmpevent){
//        		if(eve.getID() == 1)
//        			tmpcalevent = tmpevent.get(0);
//        	}
//        }
//        MWSLog.e("getCalendarID", tmpcalevent.getCalendarID() + "");
//		MWSLog.d("getID", tmpcalevent.getID() + "");
//		MWSLog.d("Description", tmpcalevent.getDescription());
//		time = new Date(Long.parseLong(tmpcalevent.getStartTime()));
//		MWSLog.d("getStartTime", ((int)time.getYear() + 1900) + "/" 
//				+ ((int)time.getMonth() + 1) + "/" + time.getDate() + "-" + time.getHours());
//		time = new Date(Long.parseLong(tmpcalevent.getEndTime()));
//		MWSLog.d("getEndTime", ((int)time.getYear() + 1900) + "/" 
//				+ ((int)time.getMonth() + 1) + "/" + time.getDate() + "-" + time.getHours());
//		MWSLog.d("getTitle", tmpcalevent.getTitle());
        
//        File path = Environment.getExternalStorageDirectory();
//        StatFs stat = new StatFs(path.getPath());
//        Log.d("reavelv", "getAvailableBlocks \t" + stat.getAvailableBlocks());
//        Log.d("reavelv", "getBlockCount \t" + stat.getBlockCount());
//        Log.d("reavelv", "getBlockSize \t" + stat.getBlockSize());
//        Log.d("reavelv", "getFreeBlocks \t" + stat.getFreeBlocks());
//
//        Log.d("reavelv", "sss \t" + (long)(stat.getBlockCount() * stat.getBlockSize()));
//        Log.d("reavelv", "avail \t" + (long)(stat.getAvailableBlocks() * stat.getBlockSize()));
        
//        ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
//        NetworkInfo net = cm.getActiveNetworkInfo();
//        Log.d("reavelv",  "getExtraInfo =" + net.getExtraInfo());
//        Log.d("reavelv",  "getReason =" + net.getReason());
//        Log.d("reavelv",  "getType =" + net.getType());
//        Log.d("reavelv",  "getSubtype =" + net.getSubtype());
//        Log.d("reavelv",  "getTypeName =" + net.getTypeName());
//        DetailedState ds = net.getDetailedState();
//        Log.d("reavelv",  "name =" + ds.name());
//        Log.d("reavelv",  "ordinal =" + ds.ordinal());
//        JSONArray jsonarr = new JSONArray();
//        JSONObject json = new JSONObject();
//        JSONObject minjson = new JSONObject();
//        
//        try {
//			json.put("test", "test1");
//			minjson.put("min", "mintest1");
//			json.put("minjson", minjson);
//			jsonarr.put(json);
//		} catch (JSONException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//        Log.w("reavelv", "JSONtest=================================================");
//        Log.w("reavelv", jsonarr.toString());
//        Log.w("reavelv", "JSONtest=================================================");
        Context themeContext;
    	int resId;
    	LayoutInflater layoutInflater;
    	View view;
    	
        try {
			themeContext = createPackageContext("com.android.testaddview_1",
					Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
//	        Log.w("reavelv", "themeContext = " + themeContext);
			resId = themeContext.getResources().getIdentifier("main", "layout", "com.android.testaddview_1");
//	        Log.w("reavelv", "resId = " + resId);
			layoutInflater = (LayoutInflater) themeContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//	        Log.w("reavelv", "layoutInflater = " + layoutInflater);
			view = layoutInflater.inflate(resId, null);
//	        Log.w("reavelv", "view = " + view);
	        view.setOnTouchListener(new OnTouchListener() {
				
				@Override
				public boolean onTouch(View v, MotionEvent event) {
//					Log.d("reavelv", "view.setOnTouchListener");
					return false;
				}
			});
			ll.addView(view);
		} catch (NameNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		c = getContentResolver().query(Albums.EXTERNAL_CONTENT_URI, null, null, null, null);
		c = getContentResolver().query(Media.EXTERNAL_CONTENT_URI, null, null, null, null);
		if(c.moveToFirst()){
			do{
				for(String str : c.getColumnNames()){
//					try{Log.d("reavelv", str + " - " + c.getString(c.getColumnIndex(str)));}
//					catch(NullPointerException e){}
				}
				
				
				//mList.add(new AlbumCLS("", ""));
			}while(c.moveToNext());
		}
		
		
		
//        try{
//        	int cameracnt = Camera.getNumberOfCameras();
//         	Log.d("reavelv", "cameracnt \t" + cameracnt);
//
//         	CameraInfo ci = null;
//             for(int i = 0 ; i < cameracnt ; i++){
//             	Camera.getCameraInfo(i, ci);
//             	Log.d("reavelv", "facing \t" + ci.facing);
//             	Log.d("reavelv", "orientation \t" + ci.orientation);
//             }
//        } catch(NoSuchMethodError e){
//        	
//        }
        
        
//        c1 = Camera.open(CameraInfo.CAMERA_FACING_BACK);
//        c1.startPreview();
//        Camera.Parameters parameters = c1.getParameters();
//		Size mCameraSize = parameters.getPreviewSize();
//		parameters.setPreviewSize(mCameraSize.width, mCameraSize.height);
////		parameters.setPreviewFormat(ImageFormat.JPEG);
//		List<int[]> Supportedrange = parameters.getSupportedPreviewFpsRange();
//		int[] range = (int[])Supportedrange.get(0);
//		int PREVIEW_FPS_MIN_INDEX = range[0]; //7000
//		int PREVIEW_FPS_MAX_INDEX = range[1]; //30000
//		parameters.setPreviewFpsRange(PREVIEW_FPS_MIN_INDEX, PREVIEW_FPS_MIN_INDEX);
//		c1.setParameters(parameters);
//		int callbackBufferSize = (mCameraSize.width*mCameraSize.height*ImageFormat.getBitsPerPixel(parameters.getPreviewFormat())/8);
//
//		Log.d("reavelv", "callbackBufferSize=" + callbackBufferSize);
//		byte[] callbackBuffer = new byte[callbackBufferSize];
//		Log.d("reavelv", "callbackBuffer=" + callbackBuffer);
//		c1.addCallbackBuffer(callbackBuffer);
//		
//		c1.setPreviewCallbackWithBuffer(new PreviewCallback() {
//			@Override
//			public void onPreviewFrame(byte[] data, Camera camera) {
//				String str = Base64.encodeToString(data, Base64.DEFAULT);
//				Log.e("reavelv", "str1 = " + str);
//				str = str.replace("\n", "");
//				wv.loadUrl("javascript:getcamera(" + str + ")");
//			}
//		});
//		c1.setPreviewCallback(new PreviewCallback() {
//			
//			@Override
//			public void onPreviewFrame(byte[] data, Camera camera) {
//				String str = Base64.encodeToString(data, Base64.DEFAULT);
//				Log.e("reavelv", "str2 = " + str);
//				str = str.replace("\n", "");
//				wv.loadUrl("javascript:getcamera(" + str + ")");
//			}
//		});
//		c1.setOneShotPreviewCallback(new PreviewCallback() {
//			
//			@Override
//			public void onPreviewFrame(byte[] data, Camera camera) {
//				String str = Base64.encodeToString(data, Base64.DEFAULT);
//				Log.e("reavelv", "str3 = " + str);
//				str = str.replace("\n", "");
//				wv.loadUrl("javascript:getcamera(\"" + str + "\")");
//			}
//		});
//		c1.startPreview();
		
		
        
        
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
        
//        final String[] CALLLOG_PROJECTION = new String[] {
//            "_id",							// 0
//            "name",							// 1
//            "number",						// 2
//            "type",							// 3
//            "date",							// 4
//        };
//        ArrayList<CallLogDetail> returnValue = new ArrayList<CallLogDetail>();
//		Cursor c = getContentResolver().query(android.provider.CallLog.Calls.CONTENT_URI, 
//				CALLLOG_PROJECTION, null, null, null);
//		if(c.moveToFirst()){
//			long milsec = c.getLong(4); 
//			Date date = new Date(milsec);
//			String time1 = ((int)date.getYear() + 1900) + "-" + ((int)date.getMonth() + 1) + "-" 
//			+ date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
//		CallLogDetail tmpcld = new CallLogDetail(c.getInt(0), c.getString(1), c.getString(2), c.getString(3), time1);
//		returnValue.add(tmpcld);
//		tmpcld = null;
//		while(c.moveToNext()){
//			milsec = c.getLong(4); 
//			date = new Date(milsec);
//			time1 = ((int)date.getYear() + 1900) + "-" + ((int)date.getMonth() + 1) + "-" 
//				+ date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
//			tmpcld = new CallLogDetail(c.getInt(0), c.getString(1), c.getString(2), c.getString(3), time1);
//			returnValue.add(tmpcld);
//			tmpcld = null;
//		}
//		}
//
//		Log.d("reavelv", "-------------------------------------------------");
//		for(CallLogDetail cdd:returnValue){
//			Log.d("reavelv", "-------------------------------------------------");
//			Log.d("reavelv", "getID() = " + cdd.getID());
//			Log.d("reavelv", "getDisplayName() = " + cdd.getDisplayName());
//			Log.d("reavelv", "getNumber() = " + cdd.getNumber());
//			Log.d("reavelv", "getTime() = " + cdd.getTime());
//			Log.d("reavelv", "getType() = " + cdd.getType());
//			
//
//			Log.d("reavelv", "-------------------------------------------------");
//		}
//		Log.d("reavelv", "-------------------------------------------------");
//        
        
        /*
        EditText et = (EditText) findViewById(R.id.timeTest);
        TextView tv = (TextView) findViewById(R.id.textviewer);
        
        tv.setWidth(width / 4);
        et.setHint("test tetetetetetest");
        Log.d(TAG, "tv.getWidth: " + tv.getLeft());
        Log.d(TAG, "tv.getWidth: " + tv.getRight());
        Log.d(TAG, "tv.getWidth: " + tv.getTop());
        Log.d(TAG, "tv.getWidth: " + tv.getBottom());
        */
        
        
        /*
        	yamaiaMediaPlayer object1 = new yamaiaMediaPlayer();
        	testerPlayer.add(object1);
        	testerPlayer.get(0).InitMediaPlayer(path1);
        	int x = testerPlayer.get(0).getDuration();
        	Log.d(TAG, "" +  x);
        	testerPlayer.get(0).start();
 getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        	yamaiaMediaPlayer object2 = new yamaiaMediaPlayer();
        	testerPlayer.add(object2);
        	testerPlayer.get(1).InitMediaPlayer(path2);
        	int y = testerPlayer.get(1).getDuration();
        	Log.d(TAG, "" +  y);
        	testerPlayer.get(1).start();
        */
        
        /*String deviceId = Settings.System.getString(getContentResolver(),
                Settings.System.ANDROID_ID);
        String userId = Settings.System.getString(getContentResolver(),
        		Settings.System.VIBRATE_ON);
        AccountManager am = AccountManager.get(this);
        Account[] acc = am.getAccounts();
        //AccountManagerFuture<Bundle> ad = am.getAuthToken(acc[0], am.getUserData(acc[0], key), null, this, null, null);
        Log.d("am", "" + am.getUserData(acc[0], null));
        
        
        // long x = Long.parseLong(userId, 16);
        TelephonyManager tm = (TelephonyManager) this.getSystemService(this.TELEPHONY_SERVICE);
        tm.getSubscriberId();
        Log.d("testID", "" + acc[0].toString());
        
*/
        

        /*
        InputStream is = getResources().openRawResource(R.drawable.icon);
        ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
        byte[] buffer = new byte[1024];
        int len;
        try{
        	while((len = is.read(buffer)) >= 0){
        		os.write(buffer, 0, len);
        	}
        }catch(IOException ioe){
        	
        }
        
        short destinationPort = 80;
        
        SmsManager smsMgr = SmsManager.getDefault();
		try {
			smsMgr.sendDataMessage("01063385308", null, destinationPort, os.toByteArray(), null, null);
			//smsMgr.sendTextMessage("01063385308", null, "testsms", null, null);	
		} catch (Exception e) {
			Log.d("test", "test - " + e.toString());
			Toast.makeText(this, "SMS ", Toast.LENGTH_SHORT).show();		
		}
        */
        /*
        Uri mmsUri = Uri.parse("content://media/mp3/m4.png");   
        Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra("sms_body", "Hi how are you");  
        intent.putExtra(Intent.EXTRA_STREAM, mmsUri);   
        intent.setType("image/png");   
        startActivity(intent); 
        */
    }
	/*
    public class MWSBroadcastReceiver extends BroadcastReceiver {
		private static final String MWS_RESULT = "SERVICE_START_RESULT";
		@Override
		public void onReceive(Context context, Intent intent) {
			String result = intent.getStringExtra(MWS_RESULT);
			if(result.equals("STARTING")) {
		    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
		    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
				Log.d("reavelv", "STARTING");
			} else if(result.equals("STARTED")) {
		    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
		    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
				Log.d("reavelv", "STARTED");
			} else if(result.equals("NOT_STARTED")) {
		    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
		    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
				Log.d("reavelv", "NOT_STARTED");
			} else{
		    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
		    	Log.d("reavelv", "lllllllllllllllllllllllllllllllllllllllllll");   
				Log.d("reavelv", result);
			}
		}
	}
	registerReceiver(m_receiver, new IntentFilter("com.lguplus.android.mws.webserver"));
	*/
	private class BatteryStatusReceiver extends BroadcastReceiver{

		@Override
		public void onReceive(Context context, Intent intent) {
			// TODO Auto-generated method stub
			String action = intent.getAction();
			Log.d("reavelv", "action = " + action);
			Log.d("reavelv", "context = " + context);
			//new IntentFilter("com.lguplus.android.mws.webserver");
			if(Intent.ACTION_BATTERY_CHANGED.equals(action))
		    {
		     Log.i("reavelv", "<reavelv>" + "PLUG:" + intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0)
		       + " / STATUS:" + intent.getIntExtra(BatteryManager.EXTRA_STATUS, BatteryManager.BATTERY_STATUS_UNKNOWN)
		       + " / LEVEL:" + intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0));
		    }
			m_battLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
			context.unregisterReceiver(m_betterybreceiver);
			//context.sendBroadcast(new Intent("test.test.test.test.test"));
		}
		
	}
    byte[] mBuffer = new byte[1024];
	 private long readAvailMem() {
	        try {
	            long memFree = 0;
	            long memCached = 0;
	            long memTotal = 0;
	            FileInputStream is = new FileInputStream("/proc/meminfo");
	            int len = is.read(mBuffer);
	            is.close();
	            final int BUFLEN = mBuffer.length;
	            for (int i=0; i<len && (memFree == 0 || memCached == 0); i++) {
	                if (matchText(mBuffer, i, "MemFree")) {
	                    i += 7;
	                    memFree = extractMemValue(mBuffer, i);
	                } else if (matchText(mBuffer, i, "Cached")) {
	                    i += 6;
	                    memCached = extractMemValue(mBuffer, i);
	                } else if (matchText(mBuffer, i, "MemTotal")) {
	                    i += 8;
	                    memTotal = extractMemValue(mBuffer, i);
	                }
	                while (i < BUFLEN && mBuffer[i] != '\n') {
	                    i++;
	                }
	            }
//	            Log.d("reavelv", "memFree = " + (memFree));
//	            Log.d("reavelv", "memCached = " + (memCached));
//	            Log.d("reavelv", "memTotal = " + (memTotal));
//	            Log.d("reavelv", "meminfo = " + (memFree + memCached));
	            return memFree + memCached;
	        } catch (java.io.FileNotFoundException e) {
	        } catch (java.io.IOException e) {
	        }
	        return 0;
	    }

	    private boolean matchText(byte[] buffer, int index, String text) {
	        int N = text.length();
	        if ((index+N) >= buffer.length) {
	            return false;
	        }
	        for (int i=0; i<N; i++) {
	            if (buffer[index+i] != text.charAt(i)) {
	                return false;
	            }
	        }
	        return true;
	    }

	    private long extractMemValue(byte[] buffer, int index) {
	        while (index < buffer.length && buffer[index] != '\n') {
	            if (buffer[index] >= '0' && buffer[index] <= '9') {
	                int start = index;
	                index++;
	                while (index < buffer.length && buffer[index] >= '0'
	                    && buffer[index] <= '9') {
	                    index++;
	                }
	                String str = new String(buffer, 0, start, index-start);
	                return ((long)Integer.parseInt(str));
	            }
	            index++;
	        }
	        return 0;
	    }
	    
	    public String toHexString(int value) {
	    	Log.d("reavelv", "======================================================");
	        char[] hexArray = new char[32];
	        int hexCnt = 32;
	        int mask = (1 << 4) - 1;	// 16吏꾩닔
	        
//	        int mask = (1 << 3) - 1;	// 2吏꾩닔
            Log.d("reavelv", "mask = " + mask);
	       
	        do {
	            int vv = value & mask;
	            Log.d("reavelv", "vv = " + vv);
	            if(vv >= 0 && vv <= 9) {
	                hexArray[--hexCnt] = (char)((int)'0' + vv);
	            } else {
	                hexArray[--hexCnt] = (char)((int)'A' + (vv-10));
	            }
	            value >>= 4;
	        } while(value > 0);
	        testwifi();
	        Log.d("reavelv", "======================================================");
	        return new String(hexArray, hexCnt, (32-hexCnt));
	    }
	    void testwifi(){
	    	ArrayList<String> IPList = new ArrayList<String>();
			try {
				Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
				
	            for (NetworkInterface ni : Collections.list(nis))
	            {
	                Enumeration<InetAddress> iis = ni.getInetAddresses();
	                for (InetAddress ia : Collections.list(iis))
	                {
	        			Log.d("reavelv", "ia.getHostName() = " + ia.getHostName());
	        			Log.d("reavelv", "getAddress() = " + new String(ia.getAddress()));
	        			Log.d("reavelv", "getHostAddress() = " + ia.getHostAddress());
	        			Log.d("reavelv", "getCanonicalHostName() = " + ia.getCanonicalHostName());
	                	
	                	if(!ia.getHostAddress().equals("127.0.0.1"))
	                		IPList.add(ia.getHostAddress());
	                }
	            }
			} catch (SocketException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
	    }
	    

		private static boolean isHexWepKey(String wepKey) {
	        final int len = wepKey.length();
	        
	        // WEP-40, WEP-104, and some vendors using 256-bit WEP (WEP-232?)
	        if (len != 10 && len != 26 && len != 58) {
	            return false;
	        }
	        
	        return isHex(wepKey);
	    }

	    private static boolean isHex(String key) {
	        for (int i = key.length() - 1; i >= 0; i--) {
	            final char c = key.charAt(i);
	            if (!(c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f')) {
	                return false;
	            }
	        }
	        
	        return true;
	    }
	    

		private static String convertToQuotedString(String string) {
	        if (TextUtils.isEmpty(string)) {
	            return "";
	        }
	        
	        final int lastPos = string.length() - 1;
	        if (lastPos < 0 || (string.charAt(0) == '"' && string.charAt(lastPos) == '"')) {
	            return string;
	        }
	        
	        return "\"" + string + "\"";
	    }	
		
		

		public static final String WPA2 = "WPA2";
		public static final String WPA = "WPA";
		public static final String WEP = "WEP";
		public static final String OPEN = "Open";
	    // For EAP Enterprise fields
	    public static final String WPA_EAP = "WPA-EAP";
	    public static final String IEEE8021X = "IEEE8021X";

	    public static final String[] EAP_METHOD = { "PEAP", "TLS", "TTLS" };
	    static final String[] SECURITY_MODES = { WEP, WPA, WPA2, WPA_EAP, IEEE8021X };
	    
	    public static final int WEP_PASSWORD_AUTO = 0;
	    public static final int WEP_PASSWORD_ASCII = 1;
	    public static final int WEP_PASSWORD_HEX = 2;

		static private void setupSecurity(WifiConfiguration config, String security, final String password) {
	        config.allowedAuthAlgorithms.clear();
	        config.allowedGroupCiphers.clear();
	        config.allowedKeyManagement.clear();
	        config.allowedPairwiseCiphers.clear();
	        config.allowedProtocols.clear();
	        
	        if (TextUtils.isEmpty(security)) {
	            security = OPEN;
	            Log.w(TAG, "Empty security, assuming open");
	        }
	        
	        if (security.equals("WEP")) {
	        	 int wepPasswordType = WEP_PASSWORD_AUTO;
	            // If password is empty, it should be left untouched
	            if (!TextUtils.isEmpty(password)) {
					if (wepPasswordType == WEP_PASSWORD_AUTO) {
	                    if (isHexWepKey(password)) {
	                        config.wepKeys[0] = "\"".concat(password).concat("\"");
	                    } else {
	                        config.wepKeys[0] = convertToQuotedString(password);
	                    }
	                } else {
	                    config.wepKeys[0] = wepPasswordType == WEP_PASSWORD_ASCII
	                            ? convertToQuotedString(password)
	                            : password;
	                }
	            }
	            
/*
	            config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
	            config.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
	            config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
	            config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
	            config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
	            config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
	             
	            config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
	            config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
	            config.wepKeys[0] = "\"".concat(password).concat("\"");
	            config.wepTxKeyIndex = 0;
*/

	            config.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
	            config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
	            
	            config.wepTxKeyIndex = 0;
	            
	            config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
	            config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);

	            config.allowedKeyManagement.set(KeyMgmt.NONE);
	            
	            config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
	            
	            config.allowedGroupCiphers.set(GroupCipher.WEP40);
	            config.allowedGroupCiphers.set(GroupCipher.WEP104);
	            
	        } else if (security.equals(WPA) || security.equals(WPA2)){
	        	

/*
	        	config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
	        	config.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
	        	config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
	        	config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
	        	config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
	        	config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
	        	 
	        	config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
	        	config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
	        	config.wepKeys[0] = "\"".concat(password).concat("\"");
	        	config.wepTxKeyIndex = 0;
*/
	        	
	        	

	        	config.wepTxKeyIndex = 0;
	            config.allowedGroupCiphers.set(GroupCipher.TKIP);
	            config.allowedGroupCiphers.set(GroupCipher.CCMP);
	            
	            config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
	            
	        	config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
	        	config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
	            
	            config.allowedPairwiseCiphers.set(PairwiseCipher.CCMP);
	            config.allowedPairwiseCiphers.set(PairwiseCipher.TKIP);

	            config.allowedProtocols.set(security.equals(WPA2) ? Protocol.RSN : Protocol.WPA);
	            
	            // If password is empty, it should be left untouched
	            if (!TextUtils.isEmpty(password)) {
	                if (password.length() == 64 && isHex(password)) {
	                    // Goes unquoted as hex
	                    config.preSharedKey = "\"".concat(password).concat("\"");
	                } else {
	                    // Goes quoted as ASCII
	                    config.preSharedKey = convertToQuotedString(password);
	                }
	            }
	            
	        } else if (security.equals(OPEN)) {
	            config.allowedKeyManagement.set(KeyMgmt.NONE);
	        } else if (security.equals(WPA_EAP) || security.equals(IEEE8021X)) {
	            config.allowedGroupCiphers.set(GroupCipher.TKIP);
	            config.allowedGroupCiphers.set(GroupCipher.CCMP);
	            if (security.equals(WPA_EAP)) {
	                config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
	            } else {
	                config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
	            }
	            if (!TextUtils.isEmpty(password)) {
	                config.preSharedKey = convertToQuotedString(password);
	            }
	        }
	    }
		public class CallLogDetail{
			private int id = -1;
			private String displayname = null, number = null, type = null, time = null;
			public CallLogDetail(int id , String displayname, String number, String type, String time) {
				this.id = id;		this.displayname = displayname;		
				this.number = number;		this.type = type;
				this.time = time;
			}
			int getID(){
				return id;
			}
			String getDisplayName(){
				return displayname;
			}
			String getNumber(){
				return number;
			}
			String getType(){
				return type;
			}
			String getTime(){
				return time;
			}
		}
		Camera c1;
}

